Part Number Hot Search : 
MUR1640 LL2012 KBPC3 20N50 105K1 HBM38PT MD2001FX 30210
Product Description
Full Text Search
 

To Download PIC24F04KL100 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2011 microchip technology inc. ds31037b-page 1 pic24f16kl402 family power management modes: ? run ? cpu, flash, sram and peripherals on ? doze ? cpu clock runs slower than peripherals ? idle ? cpu off, sram and peripherals on ? sleep ? cpu, flash and peripherals off and sram on ? low-power consumption: - run mode currents under 350 a/mhz at 1.8v - idle mode currents under 80 a/mhz at 1.8v - sleep mode currents as low as 30 na at 25c - watchdog timer as low as 210 na at 25c high-performance cpu: ? modified harvard architecture ? up to 16 mips operation @ 32 mhz ? 8 mhz internal oscillator: - 4x pll option - multiple divide options ? 17-bit x 17-bit single-cycle hardware fractional/integer multiplier ? 32-bit by 16-bit hardware divider ? 16 x 16-bit working register array ? c compiler optimized instruction set architecture (isa): - 76 base instructions - flexible addressing modes ? linear program memory addressing ? linear data memory addressing ? two address generation units (agu) for separate read and write addressing of data memory peripheral features: ? high-current sink/source (18 ma/18 ma) on all i/o pins ? configurable open-drain outputs on digital i/o pins ? up to three external interrupt sources ? two 16-bit timer/counters with selectable clock sources ? up to two 8-bit timers/counters with programmable prescalers ? two capture/compare/pwm (ccp) modules: - modules automatically configure and drive i/o - 16-bit capture with max. resolution 40 ns - 16-bit compare with max. resolution 83.3 ns - 1-bit to 10-bit pwm resolution ? up to one enhanced ccp module: - backward compatible with ccp - 1, 2 or 4 pwm outputs - programmable dead time - auto-shutdown on external event ? up to two master synchronous serial port modules (mssps) with two modes of operation: - 3-wire spi (all four modes) -i 2 c? master, multi-master and slave modes and 7-bit/10-bit addressing ? up to two uart modules: - supports rs-485, rs-232 and lin/j2602 - on-chip hardware encoder/decoder for irda ? - auto-wake-up on start bit - auto-baud detect (abd) - two-byte transmit and receive fifo buffers device pins memory peripherals ultra low-power wake-up flash program (bytes) data (bytes) data eeprom (bytes) 10-bit a/d (ch) comparators 8/16-bit timers ccp/eccp mssp uart w/irda ? pic24f16kl402 28 16k 1024 512 12 2 2/2 2/1 2 2 y pic24f08kl402 28 8k 1024 512 12 2 2/2 2/1 2 2 y pic24f16kl401 20 16k 1024 512 12 2 2/2 2/1 2 2 y pic24f08kl401 20 8k 1024 512 12 2 2/2 2/1 2 2 y pic24f08kl302 28 8k 1024 256 ? 2 2/2 2/1 2 2 y pic24f08kl301 20 8k 1024 256 ? 2 2/2 2/1 2 2 y pic24f08kl201 20 8k 512 ? 12 1 1/2 2/0 1 1 y pic24f08kl200 14 8k 512 ? 7 1 1/2 2/0 1 1 y pic24f04kl101 20 4k 512 ? ? 1 1/2 2/0 1 1 y PIC24F04KL100 14 4k 512 ? ? 1 1/2 2/0 1 1 y low-power, low-cost, general purpose 16-bit flash microcontrollers with nanowatt xlp technology
pic24f16kl402 family ds31037b-page 2 ? 2011 microchip technology inc. analog features: ? 10-bit, up to 12-channel analog-to-digital (a/d) converter: - 500 ksps conversion rate - conversion available during sleep and idle ? dual rail-to-rail analog comparators with programmable input/output configuration ? on-chip voltage reference special microcontroller features: ? operating voltage range of 1.8v to 3.6v ? 10,000 erase/write cycle endurance flash program memory, typical ? 100,000 erase/write cycle endurance data eeprom, typical ? flash and data eeprom data retention: 40 years minimum ? self-programmable under software control ? programmable reference clock output ? fail-safe clock monitor (fscm) operation: - detects clock failure and switches to on-chip, low-power rc oscillator ? power-on reset (por), power-up timer (pwrt) and oscillator start-up timer (ost) ? flexible watchdog timer (wdt): - uses its own low-power rc oscillator - windowed operating modes - programmable period of 2 ms to 131s ? in-circuit serial programming? (icsp?) and in-circuit emulation (ice) via 2 pins ? programmable high/low-voltage detect (hlvd) ? programmable brown-out reset (bor): - configurable for software controlled operation and shutdown in sleep mode - selectable trip points (1.8v, 2.7v and 3.0v) - low-power 2.0v por re-arm
? 2011 microchip technology inc. ds31037b-page 3 pic24f16kl402 family pin diagrams: pic24fxxkl302/402 note 1: analog features (indicated in red ) are not available on pic24fxxkl302 devices. 2: alternate location for i 2 c? functionality of mssp1, as determined by the i2c1sel configuration bit. 28-pin spdip/ssop/soic (1) pic24fxxkl402 mclr /v pp /ra5 v ss v dd v ref + /cv ref +/ an0 /sda2/cn2/ra0 cv ref -/ v ref - / an1 /cn3/ra1 v dd v ss pged1/ an2 /ulpwu/c1ind/c2inb/u2tx/cn4/rb0 pgec3/ascl1 (2) /sdo2/cn24/rb6 sosco/sclki/u2cts /cn0/ra4 sosci/ an15 /u2rts /cn1/rb4 sdi2/ccp3/cn9/ra7 osco/ an14 /clko/cn29/ra3 osci/ an13 /clki/cn30/ra2 c2out/ccp1/p1a/int2/cn8/ra6 u1tx/int0/cn23/rb7 sda1/t1ck/u1rts /p1d/cn21/rb9 scl1/u1cts /cn22/rb8 c1ina/c2inc/scl2/cn7/rb3 an4 /c1inb/c2ind/t3g/u1rx/cn6/rb2 pgec1/ an3 /c1inc/c2ina/u2rx/cn5/rb1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 an9 /t3ck/refo/ss1 /cn11/rb15 cv ref / an10 /c1out/flt0 /int1/cn12/rb14 an11 /sdo1/cn13/rb13 an12 /hlvdin/ss2 /ccp2/cn14/rb12 pged2/sdi1/p1b/cn16/rb10 pgec2/sck1/p1c/cn15/rb11 pged3/asda1 (2) /sck2/cn27/rb5 pic24fxxkl302 (2) 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 8 7 16 17 23 24 25 26 27 28 9 24fxxkl402 5 4 mclr / v pp /ra5 v ss v dd v ref + /cv ref +/ an0 /sda2/cn2/ra0 cv ref -/ v ref - / an1 /cn3/ra1 v dd v ss pged1/ an2 /ulpwu/c1ind/c2inb/u2tx/cn4/rb0 pgec3/ascl1 (2) /sdo2/cn24/rb6 sosco/sclki/u2cts /cn0/ra4 sosci/ an15 /u2rts /cn1/rb4 sdi2/ccp3/cn9/ra7 osco/ an14 /clko/cn29/ra3 osci/ an13 /clki/cn30/ra2 c2out/ccp1/p1a/int2/cn8/ra6 u1tx/int0/cn23/rb7 sda1/t1ck/u1rts /p1d/cn21/rb9 scl1/u1cts /cn22/rb8 c1ina/c2inc/scl2/cn7/rb3 an4 /c1inb/c2ind/t3g/u1rx/cn6/rb2 pgec1/ an3 /c1inc/c2ina/u2rx/cn5/rb1 an9 /t3ck/refo/ss1 /cn11/rb15 cv ref / an10 /c1out/flt0 /int1/cn12/rb14 an11 /sdo1/cn13/rb13 an12 /hlvdin/ss2 /ccp2/cn14/rb12 pged2/sdi1/p1b/cn16/rb10 pgec2/sck1/p1c/cn15/rb11 pged3/asda1 (2) /sck2/cn27/rb5 24fxxkl302 (2) 28-pin qfn (1) contact your microchip sales team for chip scale package (csp) availability.
pic24f16kl402 family ds31037b-page 4 ? 2011 microchip technology inc. pin diagrams: pic24fxxkl301/401 note 1: analog features (indicated in red ) are not available on pic24fxxkl301 devices. 20-pin qfn (1) 89 2 3 1 12 13 14 15 10 6 11 16 17 18 19 20 7 5 4 osco/ an14 /c1ina/c2inc/clko/cn29/ra3 pged1/ an2 /ulpwu/c1ind/c2inb/u2tx/p1c/cn4/rb0 osci/ an13 /c1inb/c2ind/clki/cn30/ra2 an4 /t3g/u1rx/cn6/rb2 pgec1/an3/c1inc/c2ina/u2rx/cn5/rb1 u1tx/int0/cn23/rb7 sda1/t1ck/u1rts /ccp3/cn21/rb9 pgec3/sosco/sclki/u2cts /cn0/ra4 pged3/sosci/ an15 /u2rts /cn1/rb4 scl1/u1cts /ss1 /cn22/rb8 an12 /hlvdin/sck1/ss2 /ccp2/cn14/rb12 an11 /sdo1/p1d/cn13/rb13 c2out/ccp1/p1a/int2/cn8/ra6 cv ref / an10 /sdi1/c1out/flt0 /int1/cn12/rb14 an9 /scl2/t3ck/refo/sck2/cn11/rb15 pged2/cv ref -/ v ref - / an1 /sdo2/cn3/ra1 pgec2/ v ref + /cv ref +/ an0 /sda2/sdi2/cn2/ra0 mclr /v pp /ra5 v dd v ss 20-pin spdip/ssop/soic (1) pic24fxxkl301 (2) mclr /v pp /ra5 osco/ an14 /c1ina/c2inc/clko/cn29/ra3 pgec2/ v ref + /cv ref +/ an0 /sda2/sdi2/cn2/ra0 pged2/cv ref -/ v ref - / an1 /sdo2/cn3/ra1 v dd v ss pged1/ an2 /ulpwu/c1ind/c2inb/u2tx/p1c/cn4/rb0 u1tx/int0/cn23/rb7 pgec3/sosco/sclki/u2cts /cn0/ra4 pged3/sosci/ an15 /u2rts /cn1/rb4 scl1/u1cts /ss1 /cn22/rb8 osci/ an13 /c1inb/c2ind/clki/cn30/ra2 an4 /t3g/u1rx/cn6/rb2 pgec1/an3/c1inc/c2ina/u2rx/cn5/rb1 1 2 3 4 5 6 7 8 9 10 20 19 18 17 16 15 14 13 12 11 an9 /scl2/t3ck/refo/sck2/cn11/rb15 cv ref / an10 /sdi1/c1out/flt0 /int1/cn12/rb14 an11 /sdo1/p1d/cn13/rb13 an12 /hlvdin/sck1/ss2 /ccp2/cn14/rb12 sda1/t1ck/u1rts /ccp3/cn21/rb9 c2out/ccp1/p1a/int2/cn8/ra6 pic24fxxkl401 pic24fxxkl301 (2) pic24fxxkl401
? 2011 microchip technology inc. ds31037b-page 5 pic24f16kl402 family pin diagrams: pic24fxxkl10x/20x 20-pin qfn (1) 89 2 3 1 12 13 14 15 10 6 11 16 17 18 19 20 7 5 4 osco/ an14 /c1ina/clko/cn29/ra3 pged1/ an2 /ulpwu/c1ind/cn4/rb0 osci/ an13 /c1inb/clki/cn30/ra2 an4 /t3g/u1rx/cn6/rb2 pgec1/ an3 /c1inc/cn5/rb1 u1tx/int0/cn23/rb7 sda1/t1ck/u1rts /cn21/rb9 pgec3/sosco/sclki/cn0/ra4 pged3/sosci/ an15 /cn1/rb4 scl1/u1cts /ss1 /cn22/rb8 an12 /hlvdin/sck1/ccp2/cn14/rb12 an11 /sdo1/cn13/rb13 ccp1/int2/cn8/ra6 cv ref /an10/sdi1/c1out/int1/cn12/rb14 an9 /t3ck/refo/cn11/rb15 pged2/cv ref -/ v ref - / an1 /cn3/ra1 pgec2/ v ref + /cv ref +/ an0 /cn2/ra0 mclr /vpp/ra5 vdd vss note 1: analog features (indicated in red ) are not available on pic24fxxkl100/101 devices. 20-pin spdip/ssop/soic (1) pic24fxxkl101 (2) mclr /v pp /ra5 osco/ an14 /c1ina/clko/cn29/ra3 pgec2/ v ref + /cv ref +/ an0 /cn2/ra0 pged2/cv ref -/ v ref - / an1 /cn3/ra1 v dd v ss pged1/ an2 /ulpwu/c1ind/cn4/rb0 u1tx/int0/cn23/rb7 pgec3/sosco/sclki/cn0/ra4 pged3/sosci/ an15 /cn1/rb4 scl1/u1cts /ss1 /cn22/rb8 osci/ an13 /c1inb/clki/cn30/ra2 an4 /t3g/u1rx/cn6/rb2 pgec1/ an3 /c1inc/cn5/rb1 1 2 3 4 5 6 7 8 9 10 20 19 18 17 16 15 14 13 12 11 an9 /t3ck/refo/cn11/rb15 cv ref /an10/sdi1/c1out/int1/cn12/rb14 an11 /sdo1/cn13/rb13 an12 /hlvdin/sck1/ccp2/cn14/rb12 sda1/t1ck/u1rts /cn21/rb9 ccp1/int2/cn8/ra6 pic24fxxkl201 mclr /v pp /ra5 pgec2/ v ref + /cv ref +/ an0 /cn2/ra0 pged2/cv ref -/ v ref - / an1 /ulpwu/cn3/ra1 v dd v ss osci/ an13 /c1inb/clki/cn30/ra2 pgec3/sosco/sclki/cn0/ra4 pged3/sosci/ an15 /hlvdin/cn1/rb4 osco/ an14 /c1ina/clko/cn29/ra3 1 2 3 4 5 6 7 14 13 12 11 10 9 8 an9 /t3ck/refo/u1rx/ss1 /int0/cn11/rb15 cv ref / an10 /t3g/u1tx/sdi1/c1out/int1/cn12/rb14 ccp1/int2/cn8/ra6 sda1/t1ck/u1rts /sdo1/ccp2/cn21/rb9 scl1/u1cts /sck1/cn22/rb8 14-pin pdip (1) pic24fxxkl101 (2) pic24fxxkl201 pic24fxxkl100 (2) pic24fxxkl200
pic24f16kl402 family ds31037b-page 6 ? 2011 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 9 2.0 guidelines for getting started with 16-bit microcontrollers ................................................................. ....................................... 21 3.0 cpu ........................................................................................................................ ................................................................... 25 4.0 memory organization ......................................................................................................... ........................................................ 31 5.0 flash program memory........................................................................................................ ...................................................... 47 6.0 data eeprom memory .......................................................................................................... ................................................... 53 7.0 resets ...................................................................................................................... .................................................................. 59 8.0 interrupt controller ........................................................................................................ ............................................................. 65 9.0 oscillator configuration ...................................... .............................................................. .......................................................... 95 10.0 power-saving features...................................................................................................... ...................................................... 105 11.0 i/o ports .................................................................................................................. ................................................................. 111 12.0 timer1 .................................................................................................................... ................................................................. 115 13.0 timer2 module .............................................................................................................. ........................................................... 117 14.0 timer3 module .............................................................................................................. ........................................................... 119 15.0 timer4 module .............................................................................................................. ........................................................... 123 16.0 capture/compare/pwm (ccp) and enhanced ccp modules......................................................................... ........................ 125 17.0 master synchronous serial port (mssp) ...................................................................................... ........................................... 135 18.0 universal asynchronous receiver transmitter (uart) ......................................................................... .................................. 149 19.0 10-bit high-speed a/d converter ............................................................................................ ................................................ 157 20.0 comparator module.......................................................................................................... ........................................................ 167 21.0 comparator voltage reference............................................................................................... ................................................. 171 22.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 173 23.0 special features ........................................................................................................... ........................................................... 175 24.0 development support........................................................................................................ ....................................................... 187 25.0 instruction set summary .................................................................................................... ...................................................... 191 26.0 electrical characteristics ................................................................................................. ......................................................... 199 27.0 packaging information...................................................................................................... ........................................................ 225 appendix a: revision history................................................................................................... .......................................................... 249 index .......................................................................................................................... ........................................................................ 251 the microchip web site ......................................................................................................... ............................................................ 255 customer change notification service ........................................................................................... ................................................... 255 customer support ............................................................................................................... ............................................................... 255 reader response ................................................................................................................ .............................................................. 256 product identification system.................................................................................................. ........................................................... 257
? 2011 microchip technology inc. ds31037b-page 7 pic24f16kl402 family to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
pic24f16kl402 family ds31037b-page 8 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 9 pic24f16kl402 family 1.0 device overview this document contains device-specific information for the following devices: the pic24f16kl402 family adds an entire range of economical, low pin count and low-power devices to microchip?s portfolio of 16-bit microcontrollers. aimed at applications that require low-power consumption but more computational ability than an 8-bit platform can provide, these devices offer a range of tailored peripheral sets that allow the designer to optimize both price point and features with no sacrifice of functionality. 1.1 core features 1.1.1 16-bit architecture central to all pic24f devices is the 16-bit modified harvard architecture, first introduced with microchip?s dspic ? digital signal controllers. the pic24f cpu core offers a wide range of enhancements, such as: ? 16-bit data and 24-bit address paths with the ability to move information between data and memory spaces ? linear addressing of up to 12 mbytes (program space) and 64 kbytes (data) ? a 16-element working register array with built-in software stack support ? a 17 x 17 hardware multiplier with support for integer math ? hardware support for 32-bit by 16-bit division ? an instruction set that supports multiple addressing modes and is optimized for high-level languages, such as c ? operational performance up to 16 mips 1.1.2 power-saving technology all of the devices in the pic24f16kl402 family incorporate a range of features that can significantly reduce power consumption during operation. key features include: ? on-the-fly clock switching: the device clock can be changed under software control to the timer1 source, or the internal, low-power rc oscillator during operation, allowing the user to incorporate power-saving ideas into their software designs. ? doze mode operation: when timing-sensitive applications, such as serial communications, require the uninterrupted operation of peripherals, the cpu clock speed can be selectively reduced, allowing incremental power savings without missing a beat. ? instruction-based power-saving modes: the microcontroller can suspend all operations, or selectively shut down its core while leaving its peripherals active, with a single instruction in software. 1.1.3 oscillator options and features the pic24f16kl402 family offers five different oscillator options, allowing users a range of choices in developing application hardware. these include: ? two crystal modes using crystals or ceramic resonators. ? two external clock modes offering the option of a divide-by-2 clock output. ? two fast internal oscillators (frcs): one with a nominal 8 mhz output and the other with a nominal 500 khz output. these outputs can also be divided under software control to provide clock speed as low as 31 khz or 2 khz. ? a phase locked loop (pll) frequency multiplier, available to the external oscillator modes and the 8 mhz frc oscillator, which allows clock speeds of up to 32 mhz. ? a separate internal rc oscillator (lprc) with a fixed 31 khz output, which provides a low-power option for timing-insensitive applications. the internal oscillator block also provides a stable reference source for the fail-safe clock monitor (fscm). this option constantly monitors the main clock source against a reference signal provided by the internal oscillator and enables the controller to switch to the internal oscillator, allowing for continued low-speed operation or a safe application shutdown. 1.1.4 easy migration regardless of the memory size, all the devices share the same rich set of peripherals, allowing for a smooth migration path as applications grow and evolve. the consistent pinout scheme used throughout the entire family also helps in migrating to the next larger device. this is true when moving between devices with the same pin count, or even jumping from 20-pin or 28-pin devices to 44-pin/48-pin devices. the pic24f family is pin compatible with devices in the dspic33 family, and shares some compatibility with the pinout schema for pic18 and dspic30. this extends the ability of applications to grow, from the relatively simple, to the powerful and complex. ? PIC24F04KL100 ? pic24f04kl101 ? pic24f08kl200 ? pic24f08kl201 ? pic24f08kl301 ? pic24f08kl302 ? pic24f08kl401 ? pic24f16kl401 ? pic24f08kl402 ? pic24f16kl402
pic24f16kl402 family ds31037b-page 10 ? 2011 microchip technology inc. 1.2 other special features ? communications: the pic24f16kl402 family incorporates multiple serial communication peripherals to handle a range of application requirements. the mssp module implements both spi and i 2 c? protocols, and supports both master and slave modes of operation for each. devices also include one of two uarts with built-in irda ? encoders/decoders. ? analog features: select members of the pic24f16kl402 family include a 10-bit a/d converter module. the a/d module incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period, as well as faster sampling speeds. the comparator modules are configurable for a wide range of operations and can be used as either a single or double comparator module. 1.3 details on individual family members devices in the pic24f16kl402 family are available in 14-pin, 20-pin and 28-pin packages. the general block diagram for all devices is shown in figure 1-1 . the pic24f16kl402 family may be thought of as four different device groups, each offering a slightly different set of features. these differ from each other in multiple ways: ? the size of the flash program memory ? the presence and size of data eeprom ? the presence of an a/d converter and the number of external analog channels available ? the number of analog comparators ? the number of general purpose timers ? the number and type of ccp modules (i.e., ccp vs. eccp) ? the number of serial communications modules (both mmsps and uarts) the general differences between the different sub-families is shown in ta b l e 1 - 1 . the feature sets for specific devices are summarized in ta b l e 1 - 2 and table 1-3 . a list of the individual pin features available on the pic24f16kl402 family devices, sorted by function, is provided in tab le 1 -4 (for pic24fxxkl40x/30x devices) and tab l e 1 - 5 (for pic24fxxkl20x/10x devices). note that this table shows the pin location of individual peripheral features and not how they are multiplexed on the same pin. this information is provided in the pinout diagrams in the beginning of this data sheet. multiplexed features are sorted by the priority given to a feature, with the highest priority peripheral being listed first. table 1-1: feature comparison fo r pic24f16kl402 family groups device group program memory (bytes) data eeprom (bytes) timers (8/16-bit) ccp and eccp serial (mssp/ uart) a/d (channels) comparators pic24fxxkl10x 4k ? 1/2 2/0 1/1 ? 1 pic24fxxkl20x 8k ? 1/2 2/0 1/1 7 or 12 1 pic24fxxkl30x 8k 256 2/2 2/1 2/2 ? 2 pic24fxxkl40x 8k or 16k 512 2/2 2/1 2/2 12 2
? 2011 microchip technology inc. ds31037b-page 11 pic24f16kl402 family table 1-2: device features for pic24f16kl40x/30x devices features pic24f16kl402 pic24f08kl402 pic24f08kl302 pic24f16kl401 pic24f08kl401 pic24f08kl301 operating frequency dc ? 32 mhz program memory (bytes) 16k 8k 8k 16k 8k 8k program memory (instructions) 5632 2816 2816 5632 2816 2816 data memory (bytes) 1024 1024 1024 1024 1024 1024 data eeprom memory (bytes) 512 512 256 512 512 256 interrupt sources (soft vectors/nmi traps) 31 (27/4) 31 (27/4) 30 (26/4) 31 (27/4) 31 (27/4) 30 (26/4) i/o ports porta<7:0> portb<15:0> porta<6:0> portb<15:12,9:7,4,2:0> total i/o pins 24 18 timers (8/16-bit) 2/2 2/2 2/2 2/2 2/2 2/2 capture/compare/pwm modules: total 333333 enhanced ccp 111111 input change notification interrupt 23 23 23 17 17 17 serial communications: uart 222222 mssp 222222 10-bit analog-to-digital module (input channels) 12 12 ? 12 12 ? analog comparators 2 2 2 2 2 2 resets (and delays) por, bor, reset instruction, mclr , wdt, illegal opcode, repeat instruction, hardware traps, configuration word mismatch ( p w r t, o s t, p l l l o c k ) instruction set 76 base instructions, multiple addressing mode variations packages 28-pin pdip/ssop/soic/qfn 20-pin spdip/ssop/soic/qfn
pic24f16kl402 family ds31037b-page 12 ? 2011 microchip technology inc. table 1-3: device features for the pic24f16kl20x/10x devices features pic24f08kl201 pic24f04kl101 pic24f08kl200 PIC24F04KL100 operating frequency dc ? 32 mhz program memory (bytes) 8k4k8k4k program memory (instructions) 2816 1408 2816 1408 data memory (bytes) 512 512 512 512 data eeprom memory (bytes) ? ? ? ? interrupt sources (soft vectors/nmi traps) 27 (23/4) 26 (22/4) 27 (23/4) 26 (22/4) i/o ports porta<6:0> portb<15:12,9:7,4,2:0> porta<5:0> portb<15:14,9:8,4,0> total i/o pins 17 12 timers (8/16-bit) 1/2 1/2 1/2 1/2 capture/compare/pwm modules: total 2 2 2 2 enhanced ccp 0 0 0 0 input change notification interrupt 17 17 11 11 serial communications: uart 1 1 1 1 mssp 1 1 1 1 10-bit analog-to-digital module (input channels) 12 ? 7 ? analog comparators 1 1 1 1 resets (and delays) por, bor, reset instruction, mclr , wdt, illegal opcode, repeat instruction, hardware traps, configuration word mismatch (pwrt, ost, pll lock) instruction set 76 base instructions, multiple addressing mode variations packages 20-pin spdip/ssop/soic/qfn 14-pin pdip/tssop
? 2011 microchip technology inc. ds31037b-page 13 pic24f16kl402 family figure 1-1: pic24f16kl402 fa mily general block diagram instruction decode and control 16 pch pcl 16 program counter 16-bit alu 23 24 data bus inst register 16 divide support inst latch 16 ea mux read agu write agu 16 16 8 interrupt controller psv and table data access control block stack control logic repeat control logic data latch data ram address latch address latch program memory data latch 16 address bus literal data 23 control signals 16 16 16 x 16 w reg array multiplier 17x17 porta (1) ra<0:7> portb (1) rb<0:15> note 1: all pins or features are not implemented on all device pinout configurations. see table 1-4 and table 1-5 for i/o port pin descriptions. comparators timer4 timer3 ccp2 a/d 10-bit ccp3 (1) mssp cn1-23 (1) uart data eeprom osci/clki osco/clko v dd , timing generation mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor frc/lprc oscillators timer2 timer1 ccp1/ hlvd precision reference band gap eccp1 (1) ulpwu v ss ulpwu 1/2 (1) 1/2 (1)
pic24f16kl402 family ds31037b-page 14 ? 2011 microchip technology inc. table 1-4: pic24f16kl40x/30x family pinout descriptions function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 28-pin spdip/ ssop/ soic 28-pin qfn an0 2 19 2 27 i ana a/d analog inputs. not available on pic24f16kl30x family devices. an1 3 20 3 28 i ana an2 4141iana an3 5252iana an4 6363iana an5 ? ? 7 4 i ana an9 18 15 26 23 i ana an10 17 14 25 22 i ana an11 16 13 24 21 i ana an12 15 12 23 20 i ana an13 7496iana an14 8 5 10 7 i ana an15 9 6 11 8 i ana ascl1 ? ? 15 12 i/o i 2 c? alternate mssp1 i 2 c clock input/output asda1 ? ? 14 11 i/o i 2 c alternate mssp1 i 2 c data input/output av dd 20 17 28 25 i ana positive supply for analog modules av ss 19 16 27 24 i ana ground reference for analog modules ccp1 14 11 20 17 i/o st ccp1/eccp1 capture input/compare and pwm output ccp2 15 12 23 20 i/o st ccp2 capture input/compare and pwm output ccp3 13 10 19 16 i/o st ccp3 capture input/compare and pwm output c1ina 8574ianacomparator 1 i nput a (+) c1inb 7463ianacomparator 1 i nput b (-) c1inc 5252ianacomparator 1 i nput c (+) c1ind 4141ianacomparator 1 i nput d (-) c1out 17 14 25 22 o ? comparator 1 output c2ina 5252ianacomparator 2 i nput a (+) c2inb 4141ianacomparator 2 i nput b (-) c2inc 8574ianacomparator 2 i nput c (+) c2ind 7463ianacomparator 2 i nput d (-) c2out 14 11 20 17 o ? comparator 2 output clk i 7496ianamain clock input clko 8 5 10 7 o ? system clock output legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
? 2011 microchip technology inc. ds31037b-page 15 pic24f16kl402 family cn0 10 7 12 9 i st interrupt-on-change inputs cn1 9 6 11 8 i st cn2 2 19 2 27 i st cn3 3 20 3 28 i st cn4 4141ist cn5 5252ist cn6 6363ist cn7 ? ? 7 4 i st cn8 14 11 20 17 i st cn9 ? ? 19 16 i st cn11 18 15 26 23 i st cn12 17 14 25 22 i st cn13 16 13 24 21 i st cn14 15 12 23 20 i st cn15 ? ? 22 19 i st cn16 ? ? 21 18 i st cn21 13 10 18 15 i st cn22 12 9 17 14 i st cn23 11 8 16 13 i st cn24 ? ? 15 12 i st cn27 ? ? 14 11 i st cn29 8 5 10 7 i st cn30 7496ist cv ref 17 14 25 22 i ana comparator voltage reference output cv ref + 2 19 2 27 i ana comparator reference positive input voltage cv ref - 3 20 3 28 i ana comparator reference negative input voltage flt0 17 14 25 22 i st eccp1 enhanced pwm fault input hlvdin 15 12 23 20 i st high/low-voltage detect input int0 11 8 16 13 i st interrupt 0 input int1 17 14 25 22 i st interrupt 1 input int2 14 11 20 17 i st interrupt 2 input mclr 1 18 1 26 i st master clear (device reset) input. this line is brought low to cause a reset. osci 7496ianamain osc illator input osco 8 5 10 7 o ana main oscillator output p1a 14 11 20 17 o ? eccp1 output a (enhanced pwm mode) p1b 5 2 21 18 o ? eccp1 output b (enhanced pwm mode) p1c 4 1 22 19 o ? eccp1 output c (enhanced pwm mode) p1d 16 13 18 15 o ? eccp1 output d (enhanced pwm mode) table 1-4: pic24f16kl40x/30x family pinout descriptions (continued) function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 28-pin spdip/ ssop/ soic 28-pin qfn legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
pic24f16kl402 family ds31037b-page 16 ? 2011 microchip technology inc. pgec1 5252i/osticsp? clock 1 pced1 4141i/osticsp data 1 pgec2 2 19 22 19 i/o st icsp clock 2 pged2 3 20 21 18 i/o st icsp data 2 pgec3 10 7 15 12 i/o st icsp clock 3 pged3 9 6 14 11 i/o st icsp data 3 ra0 2 19 2 27 i/o st porta pins ra1 320328i/ost ra2 7496i/ost ra3 8 5 10 7 i/o st ra4 10 7 12 9 i/o st ra5 118126ist ra6 14 11 20 17 i/o st ra7 ? ? 19 16 i/o st rb0 4141i/ostportb pins rb1 5252i/ost rb2 6363i/ost rb3 ? ? 7 4 i/o st rb4 9 6 11 8 i/o st rb5 ? ? 14 11 i/o st rb6 ? ? 15 12 i/o st rb7 11 8 16 13 i/o st rb8 12 9 17 14 i/o st rb9 13 10 18 15 i/o st rb10 ? ? 21 18 i/o st rb11 ? ? 22 19 i/o st rb12 15 12 23 20 i/o st rb13 16 13 24 21 i/o st rb14 17 14 25 22 i/o st rb15 18 15 26 23 i/o st refo 18 15 26 23 o ? reference clock output sck1 15 12 22 19 i/o st mssp1 spi serial input/output clock sck2 18 15 14 11 i/o st mssp2 spi serial input/output clock scl1 12 9 17 14 i/o i 2 c mssp1 i 2 c clock input/output scl2 18 15 7 4 i/o i 2 c mssp2 i 2 c clock input/output sclki 10 7 12 9 i st digital secondary clock input sda1 13 10 18 15 i/o i 2 c mssp1 i 2 c data input/output sda2 219227i/oi 2 c mssp2 i 2 c data input/output sdi1 17 14 21 18 i st mssp1 spi serial data input sdi2 2 19 19 16 i st mssp2 spi serial data input sdo1 16 13 24 21 o ? mssp1 spi serial data output sdo2 3 20 15 12 o ? mssp2 spi serial data output table 1-4: pic24f16kl40x/30x family pinout descriptions (continued) function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 28-pin spdip/ ssop/ soic 28-pin qfn legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
? 2011 microchip technology inc. ds31037b-page 17 pic24f16kl402 family sosci 9 6 11 8 i ana secondary oscillator input sosco 10 7 12 9 o ana secondary oscillator output ss1 12 9 26 23 o ? spi1 slave select ss2 15 12 23 20 o ? spi2 slave select t1ck 13 10 18 15 i st timer1 clock t3ck 18 15 26 23 i st timer3 clock t3g 6363isttimer3 external gate i nput u1cts 12 9 17 14 i st uart1 clear-to-send input u1rts 13 10 18 15 o ? uart1 request-to-send output u1rx 6363istuart1 receive u1tx 11 8 16 13 o ? uart1 transmit u2cts 10 7 12 9 i st uart2 clear-to-send input u2rts 9 6 11 8 o ? uart2 request-to-send output u2rx 5252istuart2 receive u2tx 4141o?uart2 transmit ulpwu 4141ianaultra low-power wake-up i nput v dd 20 17 13, 28 10, 25 p ? positive supply for peripheral digital logic and i/o pins v ref + 2 19 2 27 i ana a/d reference voltage input (+) v ref - 3 20 3 28 i ana a/d reference voltage input (-) v ss 19 16 8, 27 5, 24 p ? ground reference for logic and i/o pins table 1-4: pic24f16kl40x/30x family pinout descriptions (continued) function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 28-pin spdip/ ssop/ soic 28-pin qfn legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
pic24f16kl402 family ds31037b-page 18 ? 2011 microchip technology inc. table 1-5: pic24f16kl20x/10x family pinout descriptions function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 14-pin pdip/ tssop an0 2 19 2 i ana a/d analog inputs. not available on pic24f16kl10x family devices. an1 3 20 3 i ana an2 4 1 ? i ana an3 5 2 ? i ana an4 6 3 ? i ana an9 18 15 12 i ana an10 17 14 11 i ana an11 16 13 ? i ana an12 15 12 ? i ana an13 7 4 4 i ana an14 8 5 5 i ana an15 9 6 6 i ana av dd 20 17 14 i ana positive supply for analog modules av ss 19 16 13 i ana ground reference for analog modules ccp1 14 11 10 i/o st ccp1 capture input/compare and pwm output ccp2 15 12 9 i/o st ccp2 capture input/compare and pwm output c1ina 8 5 5 i ana comparator 1 input a (+) c1inb 7 4 4 i ana comparator 1 input b (-) c1inc 5 2 ? i ana comparator 1 input c (+) c1ind 4 1 ? i ana comparator 1 input d (-) c1out 17 14 11 o ? comparator 1 output clk i 7 4 9 i ana main clock input clko 8 5 10 o ? system clock output cn0 10 7 7 i st interrupt-on-change inputs cn1 9 6 6 i st cn2 2 19 2 i st cn3 3 20 3 i st cn4 4 1 ?- i st cn5 5 2 ?- i st cn6 6 3 ?- i st cn8 14 11 10 i st cn9 ?- ?- ?- i st cn11 18 15 12 i st cn12 17 14 11 i st cn13 16 13 ?- i st cn14 15 12 ?- i st cn21 13 10 9 i st cn22 12 9 8 i st cn23 11 8 ?- i st cn29 8 5 5 i st cn30 7 4 4 i st legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
? 2011 microchip technology inc. ds31037b-page 19 pic24f16kl402 family cv ref 17 14 11 i ana comparator voltage reference output cv ref + 2 19 2 i ana comparator reference positive input voltage cv ref - 3 20 3 i ana comparator reference negative input voltage hlvdin 15 12 6 i st high/low-voltage detect input int0 11 8 12 i st interrupt 0 input int1 17 14 11 i st interrupt 1 input int2 14 11 10 i st interrupt 2 input mclr 1 18 1 i st master clear (device reset) input. this line is brought low to cause a reset. osci 7 4 4 i ana main oscillator input osco 8 5 5 o ana main oscillator output pgec1 5 2 ? i/o st icsp? clock 1 pced1 4 1 ? i/o st icsp data 1 pgec2 2 19 2 i/o st icsp clock 2 pged2 3 20 3 i/o st icsp data 2 pgec3 10 7 7 i/o st icsp clock 3 pged3 9 6 6 i/o st icsp data 3 ra0 2 19 2 i/o st porta pins ra1 3 20 3 i/o st ra2 744i/ost ra3 855i/ost ra4 10 7 7 i/o st ra5 1 18 1 i st ra6 14 11 10 i/o st rb0 4 1 ? i/o st portb pins rb1 5 2 ? i/o st rb2 6 3 ? i/o st rb4 966i/ost rb7 11 8 ? i/o st rb8 12 9 8 i/o st rb9 13 10 9 i/o st rb12 15 12 ? i/o st rb13 16 13 ? i/o st rb14 17 14 11 i/o st rb15 18 15 12 i/o st refo 18 15 12 o ? reference clock output table 1-5: pic24f16kl20x/10x family pinout descriptions (continued) function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 14-pin pdip/ tssop legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
pic24f16kl402 family ds31037b-page 20 ? 2011 microchip technology inc. sck1 15 12 8 i/o st mssp1 spi serial input/output clock scl1 12 9 8 i/o i 2 c mssp1 i 2 c clock input/output sclki 10 7 12 i st digital secondary clock input sda1 13 10 9 i/o i 2 c mssp1 i 2 c data input/output sdi1 17 14 11 i st mssp1 spi serial data input sdo1 16 13 9 o ? mssp1 spi serial data output sosci 9 6 11 i ana secondary oscillator input sosco 10 7 12 o ana secondary oscillator output ss1 12 9 12 o ? spi1 slave select t1ck 13 10 9 i st timer1 clock t3ck 18 15 12 i st timer3 clock t3g 6 3 11 i st timer3 external gate input u1cts 12 9 8 i st uart1 clear-to-send input u1rts 13 10 9 o ? uart1 request-to-send output u1rx 6 3 12 i st uart1 receive u1tx 11 8 11 o ? uart1 transmit ulpwu 3 1 3 i ana ultra low-power wake-up input v dd 20 17 14 p ? positive supply for peripheral digital logic and i/o pins v ref + 2 19 2 i ana a/d reference voltage input (+) v ref - 3 20 3 i ana a/d reference voltage input (-) v ss 19 16 13 p ? ground reference for logic and i/o pins table 1-5: pic24f16kl20x/10x family pinout descriptions (continued) function pin number i/o buffer description 20-pin pdip/ ssop/ soic 20-pin qfn 14-pin pdip/ tssop legend: ttl = ttl input buffer st = schmitt trigger input buffer ana = analog level input/output i 2 c = i 2 c?/smbus input buffer
? 2011 microchip technology inc. ds31037b-page 21 pic24f16kl402 family 2.0 guidelines for getting started with 16-bit microcontrollers 2.1 basic connection requirements getting started with the pic24f16kl402 family of 16-bit microcontrollers requires attention to a minimal set of device pin connections before proceeding with development. the following pins must always be connected: ?all v dd and v ss pins (see section 2.2 ?power supply pins? ) ?all av dd and av ss pins, regardless of whether or not the analog device features are used (see section 2.2 ?power supply pins? ) ?mclr pin (see section 2.3 ?master clear (mclr) pin? ) these pins must also be connected if they are being used in the end application: ? pgecx/pgedx pins used for in-circuit serial programming? (icsp?) and debugging purposes (see section 2.4 ?icsp pins? ) ? osci and osco pins when an external oscillator source is used (see section 2.5 ?external oscillator pins? ) additionally, the following pins may be required: ?v ref +/v ref - pins are used when external voltage reference for analog modules is implemented the minimum mandatory connections are shown in figure 2-1 . figure 2-1: recommended minimum connections note: the av dd and av ss pins must always be connected, regardless of whether any of the analog modules are being used. pic24fxxkxx v dd v ss v dd v ss v ss v dd av dd av ss v dd v ss c1 r1 v dd mclr r2 c2 (1) c3 (1) c4 (1) c5 (1) c6 (1) key (all values are recommendations): c1 through c6: 0.1 ? f, 20v ceramic r1: 10 k ? r2: 100 ? to 470 ? note 1: the example shown is for a pic24f device with five v dd /v ss and av dd /av ss pairs. other devices may have more or less pairs; adjust the number of decoupling capacitors appropriately.
pic24f16kl402 family ds31037b-page 22 ? 2011 microchip technology inc. 2.2 power supply pins 2.2.1 decoupling capacitors the use of decoupling capacitors on every pair of power supply pins, such as v dd , v ss , av dd and av ss , is required. consider the following criteria when using decoupling capacitors: ? value and type of capacitor: a 0.1 ? f (100 nf), 10-20v capacitor is recommended. the capacitor should be a low-esr device, with a resonance frequency in the range of 200 mhz and higher. ceramic capacitors are recommended. ? placement on the printed circuit board: the decoupling capacitors should be placed as close to the pins as possible. it is recommended to place the capacitors on the same side of the board as the device. if space is constricted, the capacitor can be placed on another layer on the pcb using a via; however, ensure that the trace length from the pin to the capacitor is no greater than 0.25 inch (6 mm). ? handling high-frequency noise: if the board is experiencing high-frequency noise (upward of tens of mhz), add a second ceramic type capaci- tor in parallel to the above described decoupling capacitor. the value of the second capacitor can be in the range of 0.01 ? f to 0.001 ? f. place this second capacitor next to each primary decoupling capacitor. in high-speed circuit designs, consider implementing a decade pair of capacitances as close to the power and ground pins as possible (e.g., 0.1 ? f in parallel with 0.001 ? f). ? maximizing performance: on the board layout from the power supply circuit, run the power and return traces to the decoupling capacitors first, and then to the device pins. this ensures that the decoupling capacitors are first in the power chain. equally important is to keep the trace length between the capacitor and the power pins to a minimum, thereby reducing pcb trace inductance. 2.2.2 tank capacitors on boards with power traces running longer than six inches in length, it is suggested to use a tank capac- itor for integrated circuits, including microcontrollers, to supply a local power source. the value of the tank capacitor should be determined based on the trace resistance that connects the power supply source to the device, and the maximum current drawn by the device in the application. in other words, select the tank capacitor so that it meets the acceptable voltage sag at the device. typical values range from 4.7 ? f to 47 ? f. 2.3 master clear (mclr ) pin the mclr pin provides two specific device functions: device reset, and device programming and debugging. if programming and debugging are not required in the end application, a direct connection to v dd may be all that is required. the addition of other components, to help increase the application?s resistance to spurious resets from voltage sags, may be beneficial. a typical configuration is shown in figure 2-1 . other circuit designs may be implemented, depending on the application?s requirements. during programming and debugging, the resistance and capacitance that can be added to the pin must be considered. device programmers and debuggers drive the mclr pin. consequently, specific voltage levels (v ih and v il ) and fast signal transitions must not be adversely affected. therefore, specific values of r1 and c1 will need to be adjusted based on the application and pcb requirements. for example, it is recommended that the capacitor, c1, be isolated from the mclr pin during programming and debugging operations by using a jumper ( figure 2-2 ). the jumper is replaced for normal run-time operations. any components associated with the mclr pin should be placed within 0.25 inch (6 mm) of the pin. figure 2-2: example of mclr pin connections note 1: r1 ?? 10 k ? is recommended. a suggested starting value is 10 k ? . ensure that the mclr pin v ih and v il specifications are met. 2: r2 ?? 470 ? will limit any current flowing into mclr from the external capacitor, c, in the event of mclr pin breakdown, due to electrostatic discharge (esd) or electrical overstress (eos). ensure that the mclr pin v ih and v il specifications are met. c1 r2 r1 v dd mclr pic24fxxkxx jp
? 2011 microchip technology inc. ds31037b-page 23 pic24f16kl402 family 2.4 icsp pins the pgc and pgd pins are used for in-circuit serial programming? (icsp?) and debugging purposes. it is recommended to keep the trace length between the icsp connector and the icsp pins on the device as short as possible. if the icsp connector is expected to experience an esd event, a series resistor is recom- mended, with the value in the range of a few tens of ohms, not to exceed 100 ? . pull-up resistors, series diodes and capacitors on the pgc and pgd pins are not recommended as they will interfere with the programmer/debugger communica- tions to the device. if such discrete components are an application requirement, they should be removed from the circuit during programming and debugging. alter- natively, refer to the ac/dc characteristics and timing requirements information in the respective device flash programming specification for information on capacitive loading limits, and pin input voltage high (v ih ) and input low (v il ) requirements. for device emulation, ensure that the ?communication channel select? (i.e., pgcx/pgdx pins), programmed into the device, matches the physical connections for the icsp to the microchip debugger/emulator tool. for more information on available microchip development tools connection requirements, refer to section 24.0 ?development support? . 2.5 external oscillator pins many microcontrollers have options for at least two oscillators: a high-frequency primary oscillator and a low-frequency secondary oscillator (refer to section 9.0 ?oscillator configuration? for details). the oscillator circuit should be placed on the same side of the board as the device. place the oscillator circuit close to the respective oscillator pins with no more than 0.5 inch (12 mm) between the circuit components and the pins. the load capacitors should be placed next to the oscillator itself, on the same side of the board. use a grounded copper pour around the oscillator cir- cuit to isolate it from surrounding circuits. the grounded copper pour should be routed directly to the mcu ground. do not run any signal traces or power traces inside the ground pour. also, if using a two-sided board, avoid any traces on the other side of the board where the crystal is placed. layout suggestions are shown in figure 2-3 . in-line packages may be handled with a single-sided layout that completely encompasses the oscillator pins. with fine-pitch packages, it is not always possible to com- pletely surround the pins and components. a suitable solution is to tie the broken guard sections to a mirrored ground layer. in all cases, the guard trace(s) must be returned to ground. figure 2-3: suggested placement of the oscillator circuit in planning the application?s routing and i/o assign- ments, ensure that adjacent port pins and other signals, in close proximity to the oscillator, are benign (i.e., free of high frequencies, short rise and fall times, and other similar noise). gnd ` ` ` osc1 osc2 t1oso t1os i copper pour primary oscillator crystal timer1 oscillator crystal device pins primary oscillator c1 c2 t1 oscillator: c1 t1 oscillator: c2 (tied to ground) single-sided and in-line layouts: fine-pitch (dual-sided) layouts: gnd osco osci bottom layer copper pour oscillator crystal top layer copper pour c2 c1 device pins (tied to ground) (tied to ground)
pic24f16kl402 family ds31037b-page 24 ? 2011 microchip technology inc. for additional information and design guidance on oscillator circuits, please refer to these microchip application notes, available at the corporate web site ( www.microchip.com ): ? an826, ? crystal oscillator basics and crystal selection for rfpic? and picmicro ? devices? ? an849, ?basic picmicro ? oscillator design? ? an943, ?practical picmicro ? oscillator analysis and design? ? an949, ?making your oscillator work? 2.6 unused i/os unused i/o pins should be configured as outputs and driven to a logic low state. alternatively, connect a 1 k ? to 10 k ? resistor to v ss on unused pins and drive the output to logic low.
? 2011 microchip technology inc. ds31037b-page 25 pic24f16kl402 family 3.0 cpu the pic24f cpu has a 16-bit (data) modified harvard architecture with an enhanced instruction set and a 24-bit instruction word with a variable length opcode field. the program counter (pc) is 23 bits wide and addresses up to 4m instructions of user program memory space. a single-cycle instruction prefetch mechanism is used to help maintain throughput and provides predictable execution. all instructions execute in a single cycle, with the exception of instructions that change the program flow, the double-word move ( mov.d ) instruction and the table instructions. overhead-free program loop constructs are supported using the repeat instructions, which are interruptible at any point. pic24f devices have sixteen, 16-bit working registers in the programmer?s model. each of the working registers can act as a data, address or address offset register. the 16 th working register (w15) operates as a software stack pointer (ssp) for interrupts and calls. the upper 32 kbytes of the data space memory map can optionally be mapped into program space at any 16k word boundary of either program memory or data eeprom memory, defined by the 8-bit program space visibility page address (psvpag) register. the pro- gram to data space mapping feature lets any instruction access program space as if it were data space. the instruction set architecture (isa) has been significantly enhanced beyond that of the pic18, but maintains an acceptable level of backward compatibility. all pic18 instructions and addressing modes are supported, either directly, or through simple macros. many of the isa enhancements have been driven by compiler efficiency needs. the core supports inherent (no operand), relative, literal, memory direct and three groups of addressing modes. all modes support register direct and various register indirect modes. each group offers up to seven addressing modes. instructions are associated with predefined addressing modes depending upon their functional requirements. for most instructions, the core is capable of executing a data (or program data) memory read, a working register (data) read, a data memory write and a program (instruction) memory read per instruction cycle. as a result, three parameter instructions can be supported, allowing trinary operations (i.e., a + b = c) to be executed in a single cycle. a high-speed, 17-bit by 17-bit multiplier has been included to significantly enhance the core arithmetic capability and throughput. the multiplier supports signed, unsigned and mixed mode, 16-bit by 16-bit or 8-bit by 8-bit integer multiplication. all multiply instructions execute in a single cycle. the 16-bit alu has been enhanced with integer divide assist hardware that supports an iterative non-restoring divide algorithm. it operates in conjunction with the repeat instruction looping mechanism and a selection of iterative divide instructions to support 32-bit (or 16-bit), divided by a 16-bit integer signed and unsigned division. all divide operations require 19 cycles to complete, but are interruptible at any cycle boundary. the pic24f has a vectored exception scheme, with up to eight sources of non-maskable traps and up to 118 interrupt sources. each interrupt source can be assigned to one of seven priority levels. a block diagram of the cpu is illustrated in figure 3-1 . 3.1 programmer?s model figure 3-2 displays the programmer?s model for the pic24f. all registers in the programmer?s model are memory mapped and can be manipulated directly by instructions. table 3-1 provides a description of each register. all registers associated with the programmer?s model are memory mapped. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the cpu, refer to the ?pic24f family reference manual? , section 2. ?cpu? (ds39703).
pic24f16kl402 family ds31037b-page 26 ? 2011 microchip technology inc. figure 3-1: pic24f cp u core block diagram table 3-1: cpu core registers register(s) name description w0 through w15 working register array pc 23-bit program counter sr alu status register splim stack pointer limit value register tblpag table memory page address register psvpag program space visibility page address register rcount repeat loop counter register corcon cpu control register instruction decode and control pch pcl 16 program counter 16-bit alu 23 23 24 23 data bus instruction reg 16 16 x 16 w register array divide support rom latch 16 ea mux ragu wagu 16 16 8 interrupt controller psv and table data access control block stack control logic loop control logic data latch data ram address latch control signals to various blocks program memory data latch address bus 16 literal data 16 16 hardware multiplier 16 to peripheral modules address latch data eeprom
? 2011 microchip technology inc. ds31037b-page 27 pic24f16kl402 family figure 3-2: programmer?s model novz c tblpag 22 0 7 0 0 15 program counter table memory page alu status register (sr) working/address registers w0 (wreg) w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 frame pointer stack pointer psvpag 7 0 program space visibility ra 0 rcount 15 0 repeat loop counter splim stack pointer limit srl registers or bits are shadowed for push.s and pop.s instructions. 0 0 page address register 15 0 cpu control register (corcon) srh w14 w15 dc ipl 210 ?? ? ? ? ? ? ipl3 psv ???????????? ?? pc divider working registers multiplier registers 15 0 value register address register register
pic24f16kl402 family ds31037b-page 28 ? 2011 microchip technology inc. 3.2 cpu control registers register 3-1: sr: alu status register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?dc bit 15 bit 8 r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r-0 r/w-0 r/w-0 r/w-0 r/w-0 ipl2 ( 2 ) ipl1 ( 2 ) ipl0 ( 2 ) ra n ov z c bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 dc: alu half carry/borrow bit 1 = a carry-out from the 4 th low-order bit (for byte-sized data) or 8 th low-order bit (for word-sized data) of the result occurred 0 = no carry-out from the 4 th or 8 th low-order bit of the result has occurred bit 7-5 ipl<2:0>: cpu interrupt priority level (ipl) status bits ( 1 , 2 ) 111 = cpu interrupt priority level is 7 (15); user interrupts disabled 110 = cpu interrupt priority level is 6 (14) 101 = cpu interrupt priority level is 5 (13) 100 = cpu interrupt priority level is 4 (12) 011 = cpu interrupt priority level is 3 (11) 010 = cpu interrupt priority level is 2 (10) 001 = cpu interrupt priority level is 1 (9) 000 = cpu interrupt priority level is 0 (8) bit 4 ra: repeat loop active bit 1 = repeat loop in progress 0 = repeat loop not in progress bit 3 n: alu negative bit 1 = result was negative 0 = result was non-negative (zero or positive) bit 2 ov: alu overflow bit 1 = overflow occurred for signed (2?s complement) arithmetic in this arithmetic operation 0 = no overflow has occurred bit 1 z: alu zero bit 1 = an operation, which effects the z bit, has set it at some time in the past 0 = the most recent operation, which effects the z bit, has cleared it (i.e., a non-zero result) bit 0 c: alu carry/borrow bit 1 = a carry-out from the most significant bit (msb) of the result occurred 0 = no carry-out from the most signif icant bit (msb) of the result occurred note 1: the ipl status bits are read-only when nstdis (intcon1<15>) = 1 . 2: the ipl status bits are concatenated with the ipl3 bit (corcon<3>) to form the cpu interrupt priority level (ipl). the value in parentheses indicates the ipl when ipl3 = 1 .
? 2011 microchip technology inc. ds31037b-page 29 pic24f16kl402 family 3.3 arithmetic logic unit (alu) the pic24f alu is 16 bits wide and is capable of addition, subtraction, bit shifts and logic operations. unless otherwise mentioned, arithmetic operations are 2?s complement in nature. depending on the operation, the alu may affect the values of the carry (c), zero (z), negative (n), overflow (ov) and digit carry (dc) status bits in the sr register. the c and dc status bits operate as borrow and digit borrow bits, respectively, for subtraction operations. the alu can perform 8-bit or 16-bit operations, depending on the mode of the instruction that is used. data for the alu operation can come from the w register array, or data memory, depending on the addressing mode of the instruction. likewise, output data from the alu can be written to the w register array or a data memory location. the pic24f cpu incorporates hardware support for both multiplication and division. this includes a dedicated hardware multiplier and support hardware division for a 16-bit divisor. 3.3.1 multiplier the alu contains a high-speed, 17-bit x 17-bit multiplier. it supports unsigned, signed or mixed sign operation in several multiplication modes: ? 16-bit x 16-bit signed ? 16-bit x 16-bit unsigned ? 16-bit signed x 5-bit (literal) unsigned ? 16-bit unsigned x 16-bit unsigned ? 16-bit unsigned x 5-bit (literal) unsigned ? 16-bit unsigned x 16-bit signed ? 8-bit unsigned x 8-bit unsigned register 3-2: corcon: cpu control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/c-0 r/w-0 u-0 u-0 ? ? ? ?ipl3 ( 1 ) psv ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3 ipl3: cpu interrupt priority level status bit ( 1 ) 1 = cpu interrupt priority level is greater than 7 0 = cpu interrupt priority level is 7 or less bit 2 psv: program space visibility in data space enable bit 1 = program space is visible in data space 0 = program space is not visible in data space bit 1-0 unimplemented: read as ? 0 ? note 1: user interrupts are disabled when ipl3 = 1 .
pic24f16kl402 family ds31037b-page 30 ? 2011 microchip technology inc. 3.3.2 divider the divide block supports 32-bit/16-bit and 16-bit/16-bit signed and unsigned integer divide operations with the following data sizes: 1. 32-bit signed/16-bit signed divide 2. 32-bit unsigned/16-bit unsigned divide 3. 16-bit signed/16-bit signed divide 4. 16-bit unsigned/16-bit unsigned divide the quotient for all divide instructions ends up in w0 and the remainder in w1. sixteen-bit signed and unsigned div instructions can specify any w register for both the 16-bit divisor (wn), and any w register (aligned) pair (w(m + 1):wm) for the 32-bit dividend. the divide algorithm takes one cycle per bit of divisor, so both 32-bit/16-bit and 16-bit/16-bit instructions take the same number of cycles to execute. 3.3.3 multi-bit shift support the pic24f alu supports both single bit and single-cycle, multi-bit arithmetic and logic shifts. multi-bit shifts are implemented using a shifter block, capable of performing up to a 15-bit arithmetic right shift, or up to a 15-bit left shift, in a single cycle. all multi-bit shift instructions only support register direct addressing for both the operand source and result destination. a full summary of instructions that use the shift operation is provided in table 3-2 . table 3-2: instructions that use the si ngle and multi-bit shift operation instruction description asr arithmetic shift right source register by one or more bits. sl shift left source register by one or more bits. lsr logical shift right source register by one or more bits.
pic24f16kl402 family ds31037b-page 31 ? 2011 microchip technology inc. 4.0 memory organization as harvard architecture devices, the pic24f microcontrollers feature separate program and data memory space and bussing. this architecture also allows the direct access of program memory from the data space during code execution. 4.1 program address space the program address memory space of the pic24f16kl402 family is 4m instructions. the space is addressable by a 24-bit value derived from either the 23-bit program counter (pc) during program execution, or from a table operation or data space remapping, as described in section 4.3 ?interfacing program and data memory spaces? . user access to the program memory space is restricted to the lower half of the address range (000000h to 7fffffh). the exception is the use of tblrd/tblwt operations, which use tblpag<7> to permit access to the configuration bits and device id sections of the configuration memory space. memory maps for the pic24f16kl402 family of devices are shown in figure 4-1 . figure 4-1: program space memory ma p for pic24f16kl402 family devices 000000h 0000feh 000002h 000100h f8000eh f80010h fefffeh ffffffh 000004h 000200h 0001feh 000104h configuration memory space user memory space note: memory areas are not displayed to scale. reset address device config registers devid (2) goto instruction reserved alternate vector table reserved interrupt vector table pic24f04klxxx ff0000h f80000h 800000h 7fffffh reserved unimplemented read ? 0 ? reset address devid (2) goto instruction alternate vector table reserved interrupt vector table pic24f16klxxx device config registers unique id unimplemented read ? 0 ? 002bfeh 7ffe00h data eeprom flash program memory (5632 instructions) flash program memory (1408 instructions) 0015feh 000afeh reset address device config registers devid (2) goto instruction reserved alternate vector table reserved interrupt vector table pic24f08kl2xx reserved unimplemented read ? 0 ? flash program memory (2816 instructions) (512 bytes) 7fff00h reset address device config registers devid (2) goto instruction reserved alternate vector table reserved interrupt vector table pic24f08kl3xx reserved unimplemented read ? 0 ? data eeprom flash program memory (2816 instructions) (256 bytes) reset address device config registers devid (2) goto instruction reserved alternate vector table reserved interrupt vector table pic24f08kl4xx reserved unimplemented read ? 0 ? data eeprom flash program memory (2816 instructions) (512 bytes) 800802h 800808h 800800h 80080ah reserved reserved reserved unique id unique id unique id unique id reserved reserved reserved reserved
? 2011 microchip technology inc. ds31037b-page 32 pic24f16kl402 family 4.1.1 program memory organization the program memory space is organized in word-addressable blocks. although it is treated as 24 bits wide, it is more appropriate to think of each address of the program memory as a lower and upper word, with the upper byte of the upper word being unimplemented. the lower word always has an even address, while the upper word has an odd address, as shown in figure 4-2 . program memory addresses are always word-aligned on the lower word, and addresses are incremented or decremented by two during code execution. this arrangement also provides compatibility with data memory space addressing and makes it possible to access data in the program memory space. 4.1.2 hard memory vectors all pic24f devices reserve the addresses between 00000h and 000200h for hard-coded program execution vectors. a hardware reset vector is provided to redirect code execution from the default value of the pc on device reset to the actual start of code. a goto instruction is programmed by the user at 000000h, with the actual address for the start of code at 000002h. pic24f devices also have two interrupt vector tables (ivt), located from 000004h to 0000ffh and 000104h to 0001ffh. these vector tables allow each of the many device interrupt sources to be handled by separate isrs. a more detailed discussion of the interrupt vector tables is provided in section 8.1 ?interrupt vector table (ivt)? . 4.1.3 data eeprom in the pic24f16kl402 family, the data eeprom is mapped to the top of the user program memory space, starting at address, 7ffe00, and expanding up to address, 7fffff. the data eeprom is organized as 16-bit wide memory and 256 words deep. this memory is accessed using table read and write operations, similar to the user code memory. 4.1.4 device configuration words table 4-1 provides the addresses of the device configuration words for the pic24f16kl402 family. their location in the memory map is shown in figure 4-1 . for more information on device configuration words, see section 23.0 ?special features? . table 4-1: device configuration words for pic24f16kl402 family devices figure 4-2: program memory organization configuration words configuration word addresses fbs f80000 fgs f80004 foscsel f80006 fosc f80008 fwdt f8000a fpor f8000c ficd f8000e 0 8 16 pc address 000000h 000002h 000004h 000006h 23 00000000 00000000 00000000 00000000 program memory ?phantom? byte (read as ? 0 ?) least significant word most significant word instruction width 000001h 000003h 000005h 000007h msw address (lsw address)
pic24f16kl402 family ds31037b-page 33 ? 2011 microchip technology inc. 4.2 data address space the pic24f core has a separate, 16-bit wide data memory space, addressable as a single linear range. the data space is accessed using two address generation units (agus); one each for read and write operations. the data space memory map is shown in figure 4-3 . all effective addresses (eas) in the data memory space are 16 bits wide and point to bytes within the data space. this gives a data space address range of 64 kbytes or 32k words. the lower half of the data memory space (that is, when ea<15> = 0 ) is used for implemented memory addresses, while the upper half (ea<15> = 1 ) is reserved for the program space visibility (psv) area (see section 4.3.3 ?reading data from program memory using program space visibility? ). depending on the particular device, pic24f16kl402 family devices implement either 512 or 1024 words of data memory. if an ea points to a location outside of this area, an all zero word or byte will be returned. 4.2.1 data space width the data memory space is organized in byte-addressable, 16-bit wide blocks. data is aligned in data memory and registers as 16-bit words, but all the data space eas resolve to bytes. the least significant bytes (lsbs) of each word have even addresses, while the most significant bytes (msbs) have odd addresses. figure 4-3: data space memory map for pic24f16kl402 family devices (3) 0000h 07feh fffeh lsb address lsb msb msb address 0001h 07ffh 0bffh (2) ffffh 8001h 8000h 7fffh 0801h 0800h near 0bfeh (2) sfr sfr space data ram 7fffh program space visibility area note 1: upper data memory boundary for pic24fxxkl10x/20x devices. 2: upper data memory boundary for pic24fxxkl30x/40x devices. 3: data memory areas are not shown to scale. 1ffeh 1fffh space data space implemented data ram unimplemented read as ?0? 09ffh (1) 09feh (1)
? 2011 microchip technology inc. ds31037b-page 34 pic24f16kl402 family 4.2.2 data memory organization and alignment to maintain backward compatibility with pic ? devices and improve data space memory usage efficiency, the pic24f instruction set supports both word and byte operations. as a consequence of byte accessibility, all effective address (ea) calculations are internally scaled to step through word-aligned memory. for example, the core recognizes that post-modified register indirect addressing mode [ws++] will result in a value of ws + 1 for byte operations and ws + 2 for word operations. data byte reads will read the complete word, which contains the byte, using the lsb of any ea to determine which byte to select. the selected byte is placed onto the lsb of the data path. that is, data memory and the registers are organized as two parallel, byte-wide entities with shared (word) address decode, but separate write lines. data byte writes only write to the corresponding side of the array or register, which matches the byte address. all word accesses must be aligned to an even address. mis-aligned word data fetches are not supported, so care must be taken when mixing byte and word operations, or translating from 8-bit mcu code. if a mis-aligned read or write is attempted, an address error trap will be generated. if the error occurred on a read, the instruction underway is completed; if it occurred on a write, the instruction will be executed, but the write will not occur. in either case, a trap is then executed, allowing the system and/or user to examine the machine state prior to execution of the address fault. all byte loads into any w register are loaded into the lsb; the msb is not modified. a sign-extend ( se ) instruction is provided to allow the users to translate 8-bit signed data to 16-bit signed values. alternatively, for 16-bit unsigned data, users can clear the msb of any w register by executing a zero-extend ( ze ) instruction on the appropriate address. although most instructions are capable of operating on word or byte data sizes, it should be noted that some instructions operate only on words. 4.2.3 near data space the 8-kbyte area between 0000h and 1fffh is referred to as the near data space (nds). locations in this space are directly addressable via a 13-bit abso- lute address field within all memory direct instructions. the remainder of the data space is addressable indirectly. additionally, the whole data space is addressable using mov instructions, which support memory direct addressing (mda) with a 16-bit address field. for pic24f16kl402 family devices, the entire implemented data memory lies in near data space. 4.2.4 sfr space the first 2 kbytes of the near data space, from 0000h to 07ffh, are primarily occupied with special function registers (sfrs). these are used by the pic24f core and peripheral modules for controlling the operation of the device. sfrs are distributed among the modules that they control and are generally grouped together by the module. much of the sfr space contains unused addresses; these are read as ? 0 ?. the sfr space, where the sfrs are actually implemented, is provided in ta b l e 4 - 2 . each implemented area indicates a 32-byte region, where at least one address is implemented as an sfr. a complete listing of implemented sfrs, including their addresses, is provided in table 4-3 through ta b l e 4 - 1 8 . table 4-2: implemented regions of sfr data space sfr space address xx00 xx20 xx40 xx60 xx80 xxa0 xxc0 xxe0 000h core icn interrupts ? 100h timers ?tmr ? ? ? ccp ? ? ? 200h mssp uart ? ? ? ? i/o ? 300h a/d ? ? ? ? ? ? 400h ? ? ? ? ? ? ? ansel ? 500h ? ? ? ? ? ? ? ? 600h ?cmp ? ? ? ? ? ? ? 700h ? ? system nvm/pmd ? ? ? ? legend: ? = no implemented sfrs in this block.
pic24f16kl402 family ds31037b-page 35 ? 2011 microchip technology inc. table 4-3: cpu core registers map file name start addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets wreg0 0000 working register 0 0000 wreg1 0002 working register 1 0000 wreg2 0004 working register 2 0000 wreg3 0006 working register 3 0000 wreg4 0008 working register 4 0000 wreg5 000a working register 5 0000 wreg6 000c working register 6 0000 wreg7 000e working register 7 0000 wreg8 0010 working register 8 0000 wreg9 0012 working register 9 0000 wreg10 0014 working register 10 0000 wreg11 0016 working register 11 0000 wreg12 0018 working register 12 0000 wreg13 001a working register 13 0000 wreg14 001c working register 14 0000 wreg15 001e working register 15 ? 0800 splim 0020 stack pointer limit value register xxxx pcl 002e program counter low word register 0000 pch 0030 ? ? ? ? ? ? ? ? ? program counter register high byte 0000 tblpag 0032 ? ? ? ? ? ? ? ? table memory page address register 0000 psvpag 0034 ? ? ? ? ? ? ? ? program space visibility page address register 0000 rcount 0036 repeat loop counter register xxxxx sr 0042 ? ? ? ? ? ? ? dc ipl2 ipl1 ipl0 ra n ov z c 0000 corcon 0044 ? ? ? ? ? ? ? ? ? ? ? ? ipl3 psv ? ? 0000 disicnt 0052 ? ? disable interrupts counter register xxxx legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2011 microchip technology inc. ds31037b-page 36 pic24f16kl402 family table 4-4: icn register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets cnpd1 0056 cn15pde ( 1 ) cn14pde ( 1 ) cn13pde ( 1 ) cn12pde cn11pde ? cn9pde ( 2 ) cn8pde cn7pde ( 2 ) cn6pde ( 1 ) cn5pde ( 1 ) cn4pde ( 1 ) cn3pde cn2pde cn1pde cn0pde 0000 cnpd2 0058 ? cn30pde cn29pde ? cn27pde ( 2 ) ? ? cn24pde ( 2 ) cn23pde ( 1 ) cn22pde cn21pde ? ? ? ?cn16pde ( 2 ) 0000 cnen1 0062 cn15ie ( 1 ) cn14ie ( 1 ) cn13ie ( 1 ) cn12ie cn11ie ? cn9ie ( 1 ) cn8ie cn7ie ( 1 ) cn6ie ( 2 ) cn5pie ( 2 ) cn4ie ( 2 ) cn3ie cnie cn1ie cn0ie 0000 cnen2 0064 ? cn30ie cn29ie ? cn27ie ( 2 ) ? ? cn24ie ( 2 ) cn23ie ( 1 ) cn22ie cn21ie ? ? ? ? cn16ie ( 2 ) 0000 cnpu1 006e cn15pue ( 1 ) cn14pue ( 1 ) cn13pue ( 1 ) cn12pue cn11pue ? cn9pue ( 1 ) cn8pue cn7pue ( 1 ) cn6pue ( 2 ) cn5pue ( 2 ) cn4pue ( 2 ) cn3pue cn2pue cn1pue cn0pue 0000 cnpu2 0070 ? cn30pue cn29pue ? cn27pue ( 2 ) ? ? cn24pue ( 2 ) cn23pue ( 1 ) cn22pue cn21pue ? ? ? ?cn16pue ( 2 ) 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are unimplemented in 14-pin devices; read as ? 0 ?. 2: these bits are unimplemented in 14-pin and 20-pin devices; read as ? 0 ?.
pic24f16kl402 family ds31037b-page 37 ? 2011 microchip technology inc. table 4-5: interrupt controller register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 b it 3 bit 2 bit 1 bit 0 all resets intcon1 0080 nstdis ? ? ? ? ? ? ? ? ? ? matherr addrerr stkerr oscfail ? 0000 intcon2 0082 altivt disi ? ? ? ? ? ? ? ? ? ? ? int2ep int1ep int0ep 0000 ifs0 0084 nvmif ? ad1if u1txif u1rxif ? ? t3if t2if ccp2if ? ? t1if ccp1if ?int0if 0000 ifs1 0086 u2txif u2rxif int2if ?t4if ( 1 ) ? ccp3if ( 1 ) ? ? ? ? int1if cnif cmif bcl1if ssp1if 0000 ifs2 0088 ? ? ? ? ? ? ? ? ? ?t3gif ? ? ? ? ? 0000 ifs3 008a ? ? ? ? ? ? ? ? ? ? ? ? ?bcl2if ( 1 ) ssp2if ( 1 ) ? 0000 ifs4 008c ? ? ? ? ? ? ?hlvdif ? ? ? ? ?u2erifu1erif ? 0000 ifs5 008e ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ulpwuif 0000 iec0 0094 nvmie ? ad1ie u1txie u1rxie ? ? t3ie t2ie ccp2ie ? ? t1ie ccp1ie ?int0ie 0000 iec1 0096 u2txie u2rxie int2ie ?t4ie ( 1 ) ?ccp3ie ( 1 ) ? ? ? ? int1ie cnie cmie bcl1ie ssp1ie 0000 iec2 0098 ? ? ? ? ? ? ? ? ? ?t3gie ? ? ? ? ? 0000 iec3 009a ? ? ? ? ? ? ? ? ? ? ? ? ? bcl2ie ( 1 ) ssp2ie ( 1 ) ? 0000 iec4 009c ? ? ? ? ? ? ?hlvdie ? ? ? ? ? u2erie u1erie ? 0000 iec5 009e ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ulpwuie 0000 ipc0 00a4 ? t1ip2 t1ip1 t1ip0 ? ccp1ip2 ccp1ip1 ccp1ip0 ? ? ? ? ? int0ip2 int0ip1 int0ip0 4404 ipc1 00a6 ? t2ip2 t2ip1 t2ip0 ? ccp2ip2 ccp2ip1 ccp2ip0 ? ? ? ? ? ? ? ? 4400 ipc2 00a8 ? u1rxip2 u1rxip1 u1rxip0 ? ? ? ? ? ? ? ? ? t3ip2 t3ip1 t3ip0 4004 ipc3 00aa ? nvmip2 nvmip1 nvmip0 ? ? ? ? ? ad1ip2 ad1ip1 ad1ip0 ? u1txip2 u1txip1 u1txip0 4044 ipc4 00ac ? cnip2 cnip1 cnip0 ? cmip2 cmip1 cmip0 ? bcl1ip2 bcl1ip1 bcl1ip0 ? ssp1ip2 ssp1ip1 ss1ip0 4444 ipc5 00ae ? ? ? ? ? ? ? ? ? ? ? ? ? int1ip2 int1ip1 int1ip0 0004 ipc6 00b0 ?t4ip2 ( 1 ) t4ip1 ( 1 ) t4ip0 ( 1 ) ? ? ? ? ?ccp3ip2 ( 1 ) ccp3ip1 ( 1 ) ccp3ip0 ( 1 ) ? ? ? ? 4040 ipc7 00b2 ? u2txip2 u2txip1 u2txip0 ? u2rxip2 u2rxip1 u2rxip0 ? int2ip2 int2ip1 int2ip0 ? ? ? ? 4440 ipc9 00b6 ? ? ? ? ? ? ? ? ? t3gip2 t3gip1 t3gip0 ? ? ? ? 0040 ipc12 00bc ? ? ? ? ?bcl2ip2 ( 1 ) bcl2ip1 ( 1 ) bcl2ip0 ( 1 ) ?ssp2ip2 ( 1 ) ssp2ip1 ( 1 ) ssp2ip0 ( 1 ) ? ? ? ? 0440 ipc16 00c4 ? ? ? ? ? u2erip2 u2erip1 u2erip0 ? u1erip2 u1erip1 u1erip0 ? ? ? ? 0440 ipc18 00c8 ? ? ? ? ? ? ? ? ? ? ? ? ? hlvdip2 hlvdip1 hlvdip0 0004 ipc20 00cc ? ? ? ? ? ? ? ? ? ? ? ? ? ulpwuip2 ulpwuip1 ulpwuip0 0004 inttreg 00e0 cpuirq ?vhold ? ilr3 ilr2 ilr1 ilr0 ? vecnum6 vecnum5 vecnum4 vecnum3 vecnum2 vecnum1 vecnum0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x family devices; read as ? 0 ?.
? 2011 microchip technology inc. ds31037b-page 38 pic24f16kl402 family table 4-6: timer register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets tmr1 0100 timer1 register 0000 pr1 0102 timer1 period register ffff t1con 0104 ton ?tsidl ? ? ? t1ecs1 t1ecs0 ? tgate tckps1 tckps0 ? tsync tcs ? 0000 tmr2 0106 ? ? ? ? ? ? ? ? timer2 register 0000 pr2 0108 ? ? ? ? ? ? ? ? timer2 period register 00ff t2con 010a ? ? ? ? ? ? ? ? ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 0000 tmr3 010c timer3 register 0000 t3gcon 010e ? ? ? ? ? ? ? ? tmr3ge tg3pol t3gtm t3gspm t3ggo t3gval t3gss1 t3gss0 0000 t3con 0110 ? ? ? ? ? ? ? ? tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync ?tmr3on 0000 tmr4 ( 1 ) 0112 ? ? ? ? ? ? ? ? timer4 register 0000 pr4 ( 1 ) 0114 ? ? ? ? ? ? ? ? timer4 period register 00ff t4con ( 1 ) 0116 ? ? ? ? ? ? ? ? ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 0000 ccptmrs0 ( 1 ) 013c ? ? ? ? ? ? ? ? ? c3tsel0 ( 1 ) ? ? c2tsel0 ? ? c1tsel0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits and/or registers are unimplemented on pic24fxxkl10x and pic24fxxkl20x family devices; read as ? 0 ?. table 4-7: ccp/eccp register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ccp1con 0190 ? ? ? ? ? ? ? ?pm1 ( 1 ) pm0 ( 1 ) dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 ccpr1l 0192 ? ? ? ? ? ? ? ? capture/compare/pwm1 register low byte 0000 ccpr1h 0194 ? ? ? ? ? ? ? ? capture/compare/pwm1 register high byte 0000 eccp1del ( 1 ) 0196 ? ? ? ? ? ? ? ? prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 0000 eccp1as ( 1 ) 0198 ? ? ? ? ? ? ? ? eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 0000 pstr1con ( 1 ) 019a ? ? ? ? ? ? ? ?cmpl1cmpl0 ? strsync strd strc strb stra 0001 ccp2con 019c ? ? ? ? ? ? ? ? ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 0000 ccpr2l 019e ? ? ? ? ? ? ? ? capture/compare/pwm2 register low byte 0000 ccpr2h 01a0 ? ? ? ? ? ? ? ? capture/compare/pwm2 register high byte 0000 ccp3con ( 1 ) 01a8 ? ? ? ? ? ? ? ? ? ? dc3b1 dc3b0 ccp3m3 ccp3m2 ccp3m1 ccp3m0 0000 ccpr3l ( 1 ) 01aa ? ? ? ? ? ? ? ? capture/compare/pwm3 register low byte 0000 ccpr3h ( 1 ) 01ac ? ? ? ? ? ? ? ? capture/compare/pwm3 register high byte 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits and/or registers are unimplemented on pic24fxxkl10x and pic24fxxkl20x family devices; read as ? 0 ?.
pic24f16kl402 family ds31037b-page 39 ? 2011 microchip technology inc. table 4-8: mssp register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ssp1buf 0200 ? ? ? ? ? ? ? ? mssp1 receive buffer/transmit register 00xx ssp1con1 0202 ? ? ? ? ? ? ? ? wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 ssp1con2 0204 ? ? ? ? ? ? ? ? gcen ackstat ackdt acken rcen pen rsen sen 0000 ssp1con3 0206 ? ? ? ? ? ? ? ? acktim pcie scie boen sdaht sbcde ahen dhen 0000 ssp1stat 0208 ? ? ? ? ? ? ? ?smpcked/a psr/w ua bf 0000 ssp1add 020a ? ? ? ? ? ? ? ? mssp1 address register (i 2 c? slave mode) mssp1 baud rate reload register (i 2 c master mode) 0000 ssp1msk 020c ? ? ? ? ? ? ? ? mssp1 address mask register (i 2 c slave mode) 00ff ssp2buf ( 1 ) 0210 ? ? ? ? ? ? ? ? mssp2 receive buffer/transmit register 00xx ssp2con1 ( 1 ) 0212 ? ? ? ? ? ? ? ? wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 ssp2con2 ( 1 ) 0214 ? ? ? ? ? ? ? ? gcen ackstat ackdt acken rcen pen rsen sen 0000 ssp2con3 ( 1 ) 0216 ? ? ? ? ? ? ? ? acktim pcie scie boen sdaht sbcde ahen dhen 0000 ssp2stat ( 1 ) 0218 ? ? ? ? ? ? ? ?smpcked/a psr/w ua bf 0000 ssp2add ( 1 ) 021a ? ? ? ? ? ? ? ? mssp2 address register (i 2 c slave mode) mssp2 baud rate reload register (i 2 c master mode) 0000 ssp2msk ( 1 ) 021c ? ? ? ? ? ? ? ? mssp2 address mask register (i 2 c slave mode) 00ff legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits and/or registers are unimplemented on pic24fxxkl10x and pic24fxxkl20x family devices; read as ? 0 ?. table 4-9: uart register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets u1mode 0220 uarten ? usidl iren rtsmd ? uen1 uen0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel 0000 u1sta 0222 utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt urxisel1 urxisel0 adden ridle perr ferr oerr urxda 0110 u1txreg 0224 ? ? ? ? ? ? ? uart1 transmit register xxxx u1rxreg 0226 ? ? ? ? ? ? ? uart1 receive register 0000 u1brg 0228 baud rate generator prescaler register 0000 u2mode 0230 uarten ? usidl iren rtsmd ? uen1 uen0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel 0000 u2sta 0232 utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt urxisel1 urxisel0 adden ridle perr ferr oerr urxda 0110 u2txreg 0234 ? ? ? ? ? ? ? uart2 transmit register xxxx u2rxreg 0236 ? ? ? ? ? ? ? uart2 receive register 0000 u2brg 0238 baud rate generator prescaler register 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2011 microchip technology inc. ds31037b-page 40 pic24f16kl402 family table 4-10: porta register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 ( 1 ) bit 6 bit 5 ( 2 ) bit 4 bit 3 bit 2 bit 1 bit 0 all resets trisa 02c0 ? ? ? ? ? ? ? ? trisa7 trisa6 ? trisa4 trisa3 trisa2 trisa1 trisa0 00df porta 02c2 ? ? ? ? ? ? ? ? ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx lata 02c4 ? ? ? ? ? ? ? ?lata7lata6 ? lata4 lata3 lata2 lata1 lata0 xxxx odca 02c6 ? ? ? ? ? ? ? ?oda7oda6 ? oda4 oda3 oda2 oda1 oda0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these ports and their associated bits are unimplemented on 14-pin and 20-pin devices; read as ? 0 ?. 2: porta<5> is unavailable when mclr functionality is enabled (mclre configuration bit = 1 ). table 4-11: portb register map file name addr bit 15 bit 14 bit 13 ( 1 ) bit 12 ( 1 ) bit 11 ( 2 ) bit 10 ( 2 ) bit 9 bit 8 bit 7 ( 1 ) bit 6 ( 2 ) bit 5 ( 2 ) bit 4 bit 3 ( 2 ) bit 2 ( 1 ) bit 1 ( 1 ) bit 0 all resets trisb 02c8 trisb15 trisb14 trisb13 trisb12 trisb11 trisb10 trisb9 trisb8 trisb7 trisb6 trisb5 tri sb4 trisb3 trisb2 trisb1 trisb0 ffff portb 02ca rb15 rb14 rb13 rb12 rb11 rb10 rb9 rb8 rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx latb 02cc latb15 latb14 latb13 latb12 latb11 latb10 latb9 latb8 latb7 latb6 latb5 latb4 latb3 latb2 latb1 latb0 xxxx odcb 02ce odb15 odb14 odb13 odb12 odb11 odb10 odb 9 odb8 odb7 odb6 odb5 odb4 odb3 odb2 odb1 odb0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these ports and their associated bits are unimplemented on 14-pin and 20-pin devices. 2: these ports and their associated bits are unimplemented in 14-pin devices. table 4-12: pad config uration register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets padcfg1 02fc ? ? ? ? sdo2dis ( 1 ) sck2dis ( 1 ) sdo1dis sck1dis ? ? ? ? ? ? ? ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x family devices; read as ? 0 ?.
pic24f16kl402 family ds31037b-page 41 ? 2011 microchip technology inc. table 4-13: a/d register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets adc1buf0 0300 a/d buffer 0 xxxx adc1buf1 0302 a/d buffer 1 xxxx ad1con1 0320 adon ?adsidl ? ? ? form1 form0 ssrc2 ssrc1 ssrc0 ? ? asam samp done 0000 ad1con2 0322 vcfg2 vcfg1 vcfg0 offcal ?cscna ? ? ? ? smpi3 smpi2 smpi1 smpi0 bufm alts 0000 ad1con3 0324 adrc extsam pumpen samc4 samc3 samc2 samc1 samc0 ? ? adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 0000 ad1chs 0328 ch0nb ? ? ? ch0sb3 ch0sb2 ch0sb1 ch0sb0 ch0na ? ? ? ch0sa3 ch0sa2 ch0sa1 ch0sa0 0000 ad1cssl 0330 cssl15 cssl14 cssl13 cssl12 ( 1 ) cssl11 ( 1 ) cssl10 cssl9 cssl8 cssl7 cssl6 ? cssl4 ( 1 ) cssl3 ( 1 ) cssl2 ( 1 ) cssl1 cssl0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are unimplemented in 14-pin devices; read as ? 0 ?. table 4-14: analog select register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ancfg 04de ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vbgen 0000 ansa 04e0 ? ? ? ? ? ? ? ? ? ? ? ? ansa3 ansa2 ansa1 ansa0 000f ansb 04e2 ansb15 ansb14 ansb13 ansb12 ( 1 ) ? ? ? ? ? ? ? ansb4 ansb3 ( 2 ) ansb2 ( 1 ) ansb1 ( 1 ) ansb0 ( 1 ) f01f ( 3 ) legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are unimplemented in 14-pin devices; read as ? 0 ?. 2: these bits are unimplemented in 14-pin and 20-pin devices; read as ? 0 ? 3: reset value for 28-pin devices is shown. table 4-15: comparator register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets cmstat 0630 cmidl ? ? ? ? ? c2evt ( 1 ) c1evt ? ? ? ? ? ?c2outc1out xxxx cvrcon 0632 ? ? ? ? ? ? ? ? cvren cvroe cvrss cvr4 cvr3 cvr2 cvr1 cvr0 0000 cm1con 0634 con coe cpol clpwr ? ? cevt cout evpol1 evpol0 ? cref ? ? cch1 cch0 xxxx cm2con ( 1 ) 0636 con coe cpol clpwr ? ? cevt cout evpol1 evpol0 ? cref ? ? cch1 cch0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits and/or registers are unimplemented in pic24fxxkl10x/20x devices; read as ? 0 ?.
? 2011 microchip technology inc. ds31037b-page 42 pic24f16kl402 family table 4-16: system register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets rcon 0740 trapr iopuwr sboren ? ? ? cm pmslp extr swr swdten wdto sleep idle bor por (note 1 ) osccon 0742 ? cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 clklock ?lock ? cf soscdrv soscen oswen (note 2 ) clkdiv 0744 roi doze2 doze1 doze0 dozen rcdiv2 rcdiv1 rcdiv0 ? ? ? ? ? ? ? ? 3100 osctun 0748 ? ? ? ? ? ? ? ? ? ? tun5 tun4 tun3 tun2 tun1 tun0 0000 refocon 074e roen ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 ? ? ? ? ? ? ? ? 0000 hlvdcon 0756 hlvden ?hlsidl ? ? ? ? ? vdir bgvst irvst ? hlvdl3 hlvdl2 hlvdl1 hlvdl0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: rcon register reset values are dependent on the type of reset. 2: osccon register reset values are dependent on configuration fuses and by type of reset. table 4-17: nvm register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets nvmcon 0760 wr wren wrerr pgmonly ? ? ? ? ? erase nvmop5 nvmop4 nvmop3 nvmop2 nvmop1 nvmop0 0000 nvmkey 0766 ? ? ? ? ? ? ? ? nvm key register 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-18: ultra low-power wake-up register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ulpwcon 0768 ulpen ?ulpsidl ? ? ? ? ulpsink ? ? ? ? ? ? ? ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-19: pmd register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets pmd1 0770 ? t4md t3md t2md t1md ? ? ? ssp1md u2md u1md ? ? ? ? adc1md 0000 pmd2 0772 ? ? ? ? ? ? ? ? ? ? ? ? ? ccp3md ccp2md ccp1md 0000 pmd3 0774 ? ? ? ? ?cmpmd ? ? ? ? ? ? ? ? ssp2md ? 0000 pmd4 0776 ? ? ? ? ? ? ? ?ulpwumd ? ? eemd refomd ?hlvdmd ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f16kl402 family ds31037b-page 43 ? 2011 microchip technology inc. 4.2.5 software stack in addition to its use as a working register, the w15 register in pic24f devices is also used as a software stack pointer. the pointer always points to the first available free word and grows from lower to higher addresses. it predecrements for stack pops and post-increments for stack pushes, as shown in figure 4-4 . note that for a pc push during any call instruction, the msb of the pc is zero-extended before the push, ensuring that the msb is always clear. the stack pointer limit value (splim) register, associated with the stack pointer, sets an upper address boundary for the stack. splim is uninitialized at reset. as is the case for the stack pointer, splim<0> is forced to ? 0 ? as all stack operations must be word-aligned. whenever an ea is generated, using w15 as a source or destination pointer, the resulting address is compared with the value in splim. if the contents of the stack pointer (w15) and the splim register are equal, and a push operation is performed, a stack error trap will not occur. the stack error trap will occur on a subsequent push operation. thus, for example, if it is desirable to cause a stack error trap when the stack grows beyond address, 0df6, in ram, initialize the splim with the value, 0df4. similarly, a stack pointer underflow (stack error) trap is generated when the stack pointer address is found to be less than 0800h. this prevents the stack from interfering with the special function register (sfr) space. figure 4-4: call stack frame 4.3 interfacing program and data memory spaces the pic24f architecture uses a 24-bit wide program space and 16-bit wide data space. the architecture is also a modified harvard scheme, meaning that data can also be present in the program space. to use this data successfully, it must be accessed in a way that preserves the alignment of information in both spaces. apart from the normal execution, the pic24f architecture provides two methods by which the program space can be accessed during operation: ? using table instructions to access individual bytes or words anywhere in the program space ? remapping a portion of the program space into the data space, psv table instructions allow an application to read or write small areas of the program memory. this makes the method ideal for accessing data tables that need to be updated from time to time. it also allows access to all bytes of the program word. the remapping method allows an application to access a large block of data on a read-only basis, which is ideal for look-ups from a large table of static data. it can only access the least significant word (lsw) of the program word. 4.3.1 addressing program space since the address ranges for the data and program spaces are 16 and 24 bits, respectively, a method is needed to create a 23-bit or 24-bit program address from 16-bit data registers. the solution depends on the interface method to be used. for table operations, the 8-bit table memory page address register (tblpag) is used to define a 32k word region within the program space. this is concatenated with a 16-bit ea to arrive at a full 24-bit program space address. in this format, the most significant bit (msb) of tblpag is used to determine if the operation occurs in the user memory (tblpag<7> = 0 ) or the configuration memory (tblpag<7> = 1 ). for remapping operations, the 8-bit program space visibility page address register (psvpag) is used to define a 16k word page in the program space. when the msb of the ea is ? 1 ?, psvpag is concatenated with the lower 15 bits of the ea to form a 23-bit program space address. unlike the table operations, this limits remapping operations strictly to the user memory area. table 4-20 and figure 4-5 show how the program ea is created for table operations and remapping accesses from the data ea. here, p<23:0> bits refer to a program space word, whereas the d<15:0> bits refer to a data space word. note: a pc push during exception processing will concatenate the srl register to the msb of the pc prior to the push. note: a write to the splim register should not be immediately followed by an indirect read operation using w15. pc<15:0> 000000000 0 15 w15 (before call ) w15 (after call ) stack grows towards higher address 0000h pc<22:16> pop : [--w15] push : [w15++]
? 2011 microchip technology inc. ds31037b-page 44 pic24f16kl402 family table 4-20: program space address construction figure 4-5: data access from program space address generation access type access space program space address <23> <22:16> <15> <14:1> <0> instruction access (code execution) user 0 pc<22:1> 0 0xx xxxx xxxx xxxx xxxx xxx0 tblrd/tblwt (byte/word read/write) user tblpag<7:0> data ea<15:0> 0xxx xxxx xxxx xxxx xxxx xxxx configuration tblpag<7:0> data ea<15:0> 1xxx xxxx xxxx xxxx xxxx xxxx program space visibility (block remap/read) user 0 psvpag<7:0> ( 2 ) data ea<14:0> ( 1 ) 0 xxxx xxxx xxx xxxx xxxx xxxx note 1: data ea<15> is always ? 1 ? in this case, but is not used in calculating the program space address. bit 15 of the address is psvpag<0>. 2: psvpag can have only two values (? 00 ? to access program memory and ff to access data eeprom) on pic24f16kl402 family devices. 0 program counter 23 bits 1 psvpag 8 bits ea 15 bits program counter (1) select tblpag 8 bits ea 16 bits byte select 0 0 1/0 user/configuration table operations (2) program space visibility (1) space select 24 bits 23 bits (remapping) 1/0 0 note 1: the lsb of program space addres ses is always fixed as ? 0 ? in order to maintain word alignment of data in the program and data spaces. 2: table operations are not required to be word-aligned. t able read operations are permi tted in the configuration memory space.
pic24f16kl402 family ds31037b-page 45 ? 2011 microchip technology inc. 4.3.2 data access from program memory and data eeprom memory using table instructions the tblrdl and tblwtl instructions offer a direct method of reading or writing the lower word of any address within the program memory without going through data space. it also offers a direct method of reading or writing a word of any address within data eeprom memory. the tblrdh and tblwth instructions are the only method to read or write the upper 8 bits of a program space word as data. the pc is incremented by two for each successive 24-bit program word. this allows program memory addresses to directly map to data space addresses. program memory can thus be regarded as two, 16-bit word-wide address spaces, residing side by side, each with the same address range. tblrdl and tblwtl access the space which contains the least significant data word, and tblrdh and tblwth access the space which contains the upper data byte. two table instructions are provided to move byte or word-sized (16-bit) data to and from program space. both function as either byte or word operations. 1. tblrdl (table read low): in word mode, it maps the lower word of the program space location (p<15:0>) to a data address (d<15:0>). in byte mode, either the upper or lower byte of the lower program word is mapped to the lower byte of a data address. the upper byte is selected when the byte select is ? 1 ?; the lower byte is selected when it is ? 0 ?. 2. tblrdh (table read high): in word mode, it maps the entire upper word of a program address (p<23:16>) to a data address. note that d<15:8>, the ?phantom? byte, will always be ? 0 ?. in byte mode, it maps the upper or lower byte of the program word to d<7:0> of the data address, as above. note that the data will always be ? 0 ? when the upper ?phantom? byte is selected (byte select = 1 ). in a similar fashion, two table instructions, tblwth and tblwtl , are used to write individual bytes or words to a program space address. the details of their operation are explained in section 5.0 ?flash program memory? . for all table operations, the area of program memory space to be accessed is determined by the table memory page address register (tblpag). tblpag covers the entire program memory space of the device, including user and configuration spaces. when tblpag<7> = 0 , the table page is located in the user memory space. when tblpag<7> = 1 , the page is located in configuration space. figure 4-6: accessing program memory with table instructions note: the tblrdh and tblwth instructions are not used while accessing data eeprom memory. note: only table read operations will execute in the configuration memory space, and only then, in implemented areas, such as the device id. table write operations are not allowed. 0 8 16 23 00000000 00000000 00000000 00000000 ?phantom? byte tblrdh.b (wn<0> = 0 ) tblrdl.w tblrdl.b (wn<0> = 1 ) tblrdl.b (wn<0> = 0 ) 23 15 0 tblpag 00 000000h 800000h 002bfeh program space data ea<15:0> the address for the table operation is determined by the data ea within the page defined by the tblpag register. only read operations are provided; write oper ations are also valid in the user memory area.
? 2011 microchip technology inc. ds31037b-page 46 pic24f16kl402 family 4.3.3 reading data from program memory using program space visibility the upper 32 kbytes of data space may optionally be mapped into a 16k word page of the program space. this provides transparent access of stored constant data from the data space without the need to use special instructions (i.e., tblrdl/h ). program space access through the data space occurs if the msb of the data space ea is ? 1 ? and psv is enabled by setting the psv bit in the cpu control (corcon<2>) register. the location of the program memory space to be mapped into the data space is determined by the program space visibility page address (psvpag) register. this 8-bit register defines any one of 256 possible pages of 16k words in program space. in effect, psvpag functions as the upper 8 bits of the program memory address, with 15 bits of the ea functioning as the lower bits. by incrementing the pc by 2 for each program memory word, the lower 15 bits of data space addresses directly map to the lower 15 bits in the corresponding program space addresses. data reads from this area add an additional cycle to the instruction being executed, since two program memory fetches are required. although each data space address, 8000h and higher, maps directly into a corresponding program memory address (see figure 4-7), only the lower 16 bits of the 24-bit program word are used to contain the data. the upper 8 bits of any program space location, used as data, should be programmed with ? 1111 1111 ? or ? 0000 0000 ? to force a nop . this prevents possible issues should the area of code ever be accidentally executed. for operations that use psv and are executed outside of a repeat loop, the mov and mov.d instructions will require one instruction cycle, in addition to the specified execution time. all other instructions will require two instruction cycles in addition to the specified execution time. for operations that use psv, which are executed inside a repeat loop, there will be some instances that require two instruction cycles, in addition to the specified execution time of the instruction: ? execution in the first iteration ? execution in the last iteration ? execution prior to exiting the loop due to an interrupt ? execution upon re-entering the loop after an interrupt is serviced any other iteration of the repeat loop will allow the instruction accessing data, using psv, to execute in a single cycle. figure 4-7: program spac e visibility operation note: psv access is temporarily disabled during table reads/writes. 23 15 0 psvpag data space program space 0000h 8000h ffffh 00 000000h 800000h 002bfeh when corcon<2> = 1 and ea<15> = 1 : psv area the data in the page designated by psvpag is mapped into the upper half of the data memory space.... data ea<14:0> ...while the lower 15 bits of the ea specify an exact address within the psv area. this corresponds exactly to the same lower 15 bits of the actual program space address.
? 2011 microchip technology inc. ds31037b-page 47 pic24f16kl402 family 5.0 flash program memory the pic24f16kl402 family of devices contains internal flash program memory for storing and executing application code. the memory is readable, writable and erasable when operating with v dd over 1.8v. flash memory can be programmed in three ways: ? in-circuit serial programming? (icsp?) ? run-time self programming (rtsp) ? enhanced in-circuit serial programming (enhanced icsp) icsp allows a pic24f device to be serially pro- grammed while in the end application circuit. this is simply done with two lines for the programming clock and programming data (which are named pgecx and pgedx, respectively), and three other lines for power (v dd ), ground (v ss ) and master clear/program mode e ntry v oltage (mclr /v pp ). this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or custom firmware to be programmed. run-time self programming (rtsp) is accomplished using tblrd (table read) and tblwt (table write) instructions. with rtsp, the user may write program memory data in blocks of 32 instructions (96 bytes) at a time, and erase program memory in blocks of 32, 64 and 128 instructions (96,192 and 384 bytes) at a time. the nvmop<1:0> (nvmcon<1:0>) bits decide the erase block size. 5.1 table instructions and flash programming regardless of the method used, flash memory programming is done with the table read and write instructions. these allow direct read and write access to the program memory space from the data memory while the device is in normal operating mode. the 24-bit target address in the program memory is formed using the tblpag<7:0> bits and the effective address (ea) from a w register, specified in the table instruction, as depicted in figure 5-1 . the tblrdl and tblwtl instructions are used to read or write to bits<15:0> of program memory. tblrdl and tblwtl can access program memory in both word and byte modes. the tblrdh and tblwth instructions are used to read or write to bits<23:16> of program memory. tblrdh and tblwth can also access program memory in word or byte mode. figure 5-1: addressing for table registers note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on flash pro- gramming, refer to the ?pic24f family reference manual? , section 4. ?program memory? (ds39715). 0 program counter 24 bits program tblpag reg 8 bits working reg ea 16 bits using byte 24-bit ea 0 1/0 select table instruction counter using user/configuration space select
pic24f16kl402 family ds31037b-page 48 ? 2011 microchip technology inc. 5.2 rtsp operation the pic24f flash program memory array is organized into rows of 32 instructions or 96 bytes. rtsp allows the user to erase blocks of 1 row, 2 rows and 4 rows (32, 64 and 128 instructions) at a time, and to program one row at a time. the 1-row (96 bytes), 2-row (192 bytes) and 4-row (384 bytes) erase blocks and single row write block (96 bytes) are edge-aligned, from the beginning of program memory. when data is written to program memory using tblwt instructions, the data is not written directly to memory. instead, data written using table writes is stored in holding latches until the programming sequence is executed. any number of tblwt instructions can be executed and a write will be successfully performed. however, 32 tblwt instructions are required to write the full row of memory. the basic sequence for rtsp programming is to set up a table pointer, then do a series of tblwt instructions to load the buffers. programming is performed by setting the control bits in the nvmcon register. data can be loaded in any order and the holding regis- ters can be written to multiple times before performing a write operation. subsequent writes, however, will wipe out any previous writes. all of the table write operations are single-word writes (two instruction cycles), because only the buffers are writ- ten. a programming cycle is required for programming each row. 5.3 enhanced in-circuit serial programming enhanced icsp uses an on-board bootloader, known as the program executive, to manage the programming process. using an spi data frame format, the program executive can erase, program and verify program memory. for more information on enhanced icsp, see the device programming specification. 5.4 control registers there are two sfrs used to read and write the program flash memory: nvmcon and nvmkey. the nvmcon register ( register 5-1 ) controls the blocks that need to be erased, which memory type is to be programmed and when the programming cycle starts. nvmkey is a write-only register that is used for write protection. to start a pr ogramming or erase sequence, the user must consecutively write 55h and aah to the nvmkey register. for more information, refer to section 5.5 ?programming operations? . 5.5 programming operations a complete programming sequence is necessary for programming or erasing the internal flash in rtsp mode. during a programming or erase operation, the processor stalls (waits) until the operation is finished. setting the wr bit (nvmcon<15>) starts the operation and the wr bit is automatically cleared when the operation is finished. note: writing to a location multiple times without erasing it is not recommended.
? 2011 microchip technology inc. ds31037b-page 49 pic24f16kl402 family register 5-1: nvmcon: flash memory control register r/so-0, hc r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 wr wren wrerr pgmonly ( 4 ) ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? erase nvmop5 ( 1 ) nvmop4 ( 1 ) nvmop3 ( 1 ) nvmop2 ( 1 ) nvmop1 ( 1 ) nvmop0 ( 1 ) bit 7 bit 0 legend: so = settable only bit hc = hardware clearable bit -n = value at por ?1? = bit is set r = readable bit w = writable bit ?0? = bit is cleared x = bit is unknown u = unimplemented bit, read as ?0? bit 15 wr: write control bit 1 = initiates a flash memory program or erase operation. the operation is self-timed and the bit is cleared by hardware once the operation is complete. 0 = program or erase operation is complete and inactive bit 14 wren: write enable bit 1 = enable flash program/erase operations 0 = inhibit flash program/erase operations bit 13 wrerr: write sequence error flag bit 1 = an improper program or erase sequ ence attempt, or termination, has occurred (bit is set automatically on any set attempt of the wr bit) 0 = the program or erase operation completed normally bit 12 pgmonly: program only enable bit ( 4 ) bit 11-7 unimplemented: read as ? 0 ? bit 6 erase: erase/program enable bit 1 = perform the erase operation specified by nvmop<5:0> on the next wr command 0 = perform the program operation specified by nvmop<5:0> on the next wr command bit 5-0 nvmop<5:0>: programming operation command byte bits ( 1 ) erase operations (when erase bit is ? 1 ?): 1010xx = erase entire boot block (including code-protected boot block) ( 2 ) 1001xx = erase entire memory (including boot block, configuration block, general block) ( 2 ) 011010 = erase 4 rows of flash memory ( 3 ) 011001 = erase 2 rows of flash memory ( 3 ) 011000 = erase 1 row of flash memory ( 3 ) 0101xx = erase entire configuration block (except code protection bits) 0100xx = erase entire data eeprom ( 4 ) 0011xx = erase entire general memory block programming operations 0001xx = write 1 row of flash memory (when erase bit is ? 0 ?) ( 3 ) note 1: all other combinations of the nvmop<5:0> bits are no operation. 2: available in icsp? mode only. refer to the device programming specification. 3: the address in the table pointer decides which rows will be erased. 4: this bit is used only while accessing data eeprom. it is implemented only in devices with data eeprom.
pic24f16kl402 family ds31037b-page 50 ? 2011 microchip technology inc. 5.5.1 programming algorithm for flash program memory the user can program one row of flash program memory at a time by erasing the programmable row. the general process is as follows: 1. read a row of program memory (32 instructions) and store in data ram. 2. update the program data in ram with the desired new data. 3. erase a row (see example 5-1 ): a) set the nvmop bits (nvmcon<5:0>) to ? 011000 ? to configure for row erase. set the erase (nvmcon<6>) and wren (nvmcon<14>) bits. b) write the starting address of the block to be erased into the tblpag and w registers. c) write 55h to nvmkey. d) write aah to nvmkey. e) set the wr bit (nvmcon<15>). the erase cycle begins and the cpu stalls for the duration of the erase cycle. when the erase is done, the wr bit is cleared automatically. 4. write the first 32 instructions from data ram into the program memory buffers (see example 5-1 ). 5. write the program block to flash memory: a) set the nvmop bits to ? 000100 ? to configure for row programming. clear the erase bit and set the wren bit. b) write 55h to nvmkey. c) write aah to nvmkey. d) set the wr bit. the programming cycle begins and the cpu stalls for the duration of the write cycle. when the write to flash memory is done, the wr bit is cleared automatically. for protection against accidental operations, the write initiate sequence for nvmkey must be used to allow any erase or program operation to proceed. after the programming command has been executed, the user must wait for the programming time until programming is complete. the two instructions following the start of the programming sequence should be nop s, as shown in example 5-5 . example 5-1: erasing a program memo ry row ? assembly language code ; set up nvmcon for row erase operation mov #0x4058, w0 ; mov w0, nvmcon ; initialize nvmcon ; init pointer to row to be erased mov #tblpage(prog_addr), w0 ; mov w0, tblpag ; initialize pm page boundary sfr mov #tbloffset(prog_addr), w0 ; initialize in-page ea[15:0] pointer tblwtl w0, [w0] ; set base address of erase block disi #5 ; block all interrupts for next 5 instructions mov #0x55, w0 mov w0, nvmkey ; write the 55 key mov #0xaa, w1 ; mov w1, nvmkey ; write the aa key bset nvmcon, #wr ; start the erase sequence nop ; insert two nops after the erase nop ; command is asserted
? 2011 microchip technology inc. ds31037b-page 51 pic24f16kl402 family example 5-2: erasing a program me mory row ? ?c? language code example 5-3: loading the write bu ffers ? assembly language code // c example using mplab c30 int __attribute__ ((space(auto_psv))) progaddr = &progaddr; // global variable located in pgm memory unsigned int offset; //set up pointer to the first memory location to be written tblpag = __builtin_tblpage(&progaddr); // initialize pm page boundary sfr offset = &progaddr & 0xffff; // initialize lower word of address __builtin_tblwtl(offset, 0x0000); // set base address of erase block // with dummy latch write nvmcon = 0x4058; // initialize nvmcon asm("disi #5"); // bl ock all interrupts for next 5 // instructions __builtin_write_nvm(); // c30 function to perform unlock // sequence and set wr ; set up nvmcon for row programming operations mov #0x4004, w0 ; mov w0, nvmcon ; initialize nvmcon ; set up a pointer to the first program memory location to be written ; program memory selected, and writes enabled mov #0x0000, w0 ; mov w0, tblpag ; initialize pm page boundary sfr mov #0x6000, w0 ; an example program memory address ; perform the tblwt instructions to write the latches ; 0th_program_word mov #low_word_0, w2 ; mov #high_byte_0, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; 1st_program_word mov #low_word_1, w2 ; mov #high_byte_1, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; 2nd_program_word mov #low_word_2, w2 ; mov #high_byte_2, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ? ? ? ; 32nd_program_word mov #low_word_31, w2 ; mov #high_byte_31, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0] ; write pm high byte into program latch
pic24f16kl402 family ds31037b-page 52 ? 2011 microchip technology inc. example 5-4: loading the write buffers ? ?c? language code example 5-5: initiating a programming sequence ? assembly language code example 5-6: initiating a programmi ng sequence ? ?c? language code // c example using mplab c30 #define num_instruction_per_row 64 int __attribute__ ((space(auto_psv))) progaddr = &progaddr; // global variable located in pgm memory unsigned int offset; unsigned int i; unsigned int progdata[2*num_instruction_per_row]; // buffer of data to write //set up nvmcon for row programming nvmcon = 0x4004; // initialize nvmcon //set up pointer to the first memory location to be written tblpag = __builtin_tblpage(&progaddr); // initialize pm page boundary sfr offset = &progaddr & 0xffff; // initialize lower word of address //perform tblwt instructions to write necessary number of latches for(i=0; i < 2*num_instruction_per_row; i++) { __builtin_tblwtl(offset, progdata[i++]); // write to address low word __builtin_tblwth(offset, progdata[i]); // write to upper byte offset = offset + 2; // increment address } disi #5 ; block all interrupts for next 5 instructions mov #0x55, w0 mov w0, nvmkey ; write the 55 key mov #0xaa, w1 ; mov w1, nvmkey ; write the aa key bset nvmcon, #wr ; start the erase sequence nop ; 2 nops required after setting wr nop ; btsc nvmcon, #15 ; wait for the sequence to be completed bra $-2 ; // c example using mplab c30 asm("disi #5"); // block all interrupts for next 5 instructions __builtin_write_nvm(); // perform unlock sequence and set wr
? 2011 microchip technology inc. ds31037b-page 53 pic24f16kl402 family 6.0 data eeprom memory the data eeprom memory is a nonvolatile memory (nvm), separate from the program and volatile data ram. data eeprom memory is based on the same flash technology as program memory, and is optimized for both long retention and a higher number of erase/write cycles. the data eeprom is mapped to the top of the user pro- gram memory space, with the top address at program memory address, 7fffffh. for pic24fxxkl4xx devices, the size of the data eeprom is 256 words (7ffe00h to 7fffffh). for pic24fxxkl3xx devices, the size of the data eeprom is 128 words (7fff00h to 7fffffh). the data eeprom is not implemented in pic24f08kl20x or pic24f04kl10x devices. the data eeprom is organized as 16-bit wide memory. each word is directly addressable, and is readable and writable during normal operation over the entire v dd range. unlike the flash program memory, normal program execution is not stopped during a data eeprom program or erase operation. the data eeprom programming operations are controlled using the three nvm control registers: ? nvmcon: nonvolatile memory control register ? nvmkey: nonvolatile memory key register ? nvmadr: nonvolatile memory address register 6.1 nvmcon register the nvmcon register ( register 6-1 ) is also the primary control register for data eeprom program/erase operations. the upper byte contains the control bits used to start the program or erase cycle, and the flag bit to indicate if the operation was successfully performed. the lower byte of nvmcom configures the type of nvm operation that will be performed. 6.2 nvmkey register the nvmkey is a write-only register that is used to prevent accidental writes or erasures of data eeprom locations. to start any programming or erase sequence, the following instructions must be executed first, in the exact order provided: 1. write 55h to nvmkey. 2. write aah to nvmkey. after this sequence, a write will be allowed to the nvmcon register for one instruction cycle. in most cases, the user will simply need to set the wr bit in the nvmcon register to start the program or erase cycle. interrupts should be disabled during the unlock sequence. the mplab ? c30 c compiler provides a defined library procedure ( builtin_write_nvm ) to perform the unlock sequence. example 6-1 illustrates how the unlock sequence can be performed with in-line assembly. example 6-1: data eeprom unlock sequence note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on data eeprom, refer to the ?pic24f family reference manual? , section 5. ?data eeprom? (ds39720). //disable interrupts for 5 instructions asm volatile("disi #5"); //issue unlock sequence asm volatile("mov #0x55, w0 \n" "mov w0, nvmkey \n" "mov #0xaa, w1 \n" "mov w1, nvmkey \n"); // perform write/erase operations asm volatile ("bset nvmcon, #wr \n" "nop \n" "nop \n");
pic24f16kl402 family ds31037b-page 54 ? 2011 microchip technology inc. register 6-1: nvmcon: nonvolat ile memory control register r/s-0, hc r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 wr wren wrerr pgmonly ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? erase nvmop5 ( 1 ) nvmop4 ( 1 ) nvmop3 ( 1 ) nvmop2 ( 1 ) nvmop1 ( 1 ) nvmop0 ( 1 ) bit 7 bit 0 legend: hc = hardware clearable u = unimplemented bit, read as ?0? r = readable bit w = writable bit s = settable bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 wr: write control bit (program or erase) 1 = initiates a data eeprom erase or write cycle (can be set but not cleared in software) 0 = write cycle is complete (cleared automatically by hardware) bit 14 wren: write enable bit (erase or program) 1 = enable an erase or program operation 0 = no operation allowed (device clears this bit on completion of the write/erase operation) bit 13 wrerr: flash error flag bit 1 = a write operation is prematurely terminated (any mclr or wdt reset during programming operation) 0 = the write operation completed successfully bit 12 pgmonly: program only enable bit 1 = write operation is executed without erasing target address(es) first 0 = automatic erase-before-write. write operations are preceded automatically by an erase of target address(es). bit 11-7 unimplemented: read as ? 0 ? bit 6 erase: erase operation select bit 1 = perform an erase operation when wr is set 0 = perform a write operation when wr is set bit 5-0 nvmop<5:0>: programming operation command byte bits ( 1 ) erase operations (when erase bit is ? 1 ?): 011010 = erase 8 words 011001 = erase 4 words 011000 = erase 1 word 0100xx = erase entire data eeprom programming operations (when erase bit is ? 0 ?): 001xxx = write 1 word note 1: these nvmop configurations are unimplemented on pic24f04kl10x and pic24f08kl20x devices.
? 2011 microchip technology inc. ds31037b-page 55 pic24f16kl402 family 6.3 nvm address register as with flash program memory, the nvm address registers, nvmadru and nvmadr, form the 24-bit effective address (ea) of the selected row or word for data eeprom operations. the nvmadru register is used to hold the upper 8 bits of the ea, while the nvmadr register is used to hold the lower 16 bits of the ea. these registers are not mapped into the special function register (sfr) space; instead, they directly capture the ea<23:0> of the last table write instruction that has been executed and selects the data eeprom row to erase. figure 6-1 depicts the program memory ea that is formed for programming and erase operations. like program memory operations, the least significant bit (lsb) of nvmadr is restricted to even addresses. this is because any given address in the data eeprom space consists of only the lower word of the program memory width; the upper word, including the uppermost ?phantom byte?, is unavailable. this means that the lsb of a data eeprom address will always be ? 0 ?. similarly, the most significant bit (msb) of nvmadru is always ? 0 ?, since all addresses lie in the user program space. figure 6-1: data eeprom addressing with tblpag and nvm address registers 6.4 data eeprom operations the eeprom block is accessed using table read and write operations, similar to those used for program memory. the tblwth and tblrdh instructions are not required for data eeprom operations since the memory is only 16 bits wide (data on the lower address is valid only). the following programming operations can be performed on the data eeprom: ? erase one, four or eight words ? bulk erase the entire data eeprom ? write one word ? read one word the library procedures are used in the code examples detailed in the following sections. general descriptions of each process are provided for users who are not using the c30 compiler libraries. 24-bit pm address tblpag nvmadr w register ea 7fh xxxxh 0 0 nvmadru note: unexpected results will be obtained if the user attempts to read the eeprom while a programming or erase operation is underway. the c30 c compiler includes library procedures to automatically perform the table read and table write operations, manage the table pointer and write buffers, and unlock and initiate memory write sequences. this eliminates the need to create assembler macros or time critical routines in c for each application.
pic24f16kl402 family ds31037b-page 56 ? 2011 microchip technology inc. 6.4.1 erase data eeprom the data eeprom can be fully erased, or can be partially erased, at three different sizes: one word, four words or eight words. the bits, nvmop<1:0> (nvmcon<1:0>), decide the number of words to be erased. to erase partially from the data eeprom, the following sequence must be followed: 1. configure nvmcon to erase the required number of words: one, four or eight. 2. load tblpag and wreg with the eeprom address to be erased. 3. clear nvmif status bit and enable the nvm interrupt (optional). 4. write the key sequence to nvmkey. 5. set the wr bit to begin erase cycle. 6. either poll the wr bit or wait for the nvm interrupt (nvmif is set). a typical erase sequence is provided in example 6-2 . this example shows how to do a one-word erase. similarly, a four-word erase and an eight-word erase can be done. this example uses c library procedures to manage the table pointer ( builtin_tblpage and builtin_tbloffset ) and the erase page pointer ( builtin_tblwtl ). the memory unlock sequence ( builtin_write_nvm ) also sets the wr bit to initiate the operation and returns control when complete. example 6-2: single-word erase int __attribute__ ((space(eedata))) eedata = 0x1234; // global variable located in eeprom unsigned int offset; // set up nvmcon to erase one word of data eeprom nvmcon = 0x4058; // set up a pointer to the eeprom location to be erased tblpag = __builtin_tblpage(&eedata); // initialize ee data page pointer offset = __builtin_tbloffset(&eedata); // initizlize lower word of address __builtin_tblwtl(offset, 0); // write eeprom data to write latch asm volatile ("disi #5"); // disable interrupts for 5 instructions __builtin_write_nvm(); // issue unlock sequence & start write cycle while(nvmconbits.wr=1); // optional: poll wr bit to wait for // write sequence to complete
? 2011 microchip technology inc. ds31037b-page 57 pic24f16kl402 family 6.4.1.1 data eeprom bulk erase to erase the entire data eeprom (bulk erase), the address registers do not need to be configured because this operation affects the entire data eeprom. the following sequence helps in performing a bulk erase: 1. configure nvmcon to bulk erase mode. 2. clear nvmif status bit and enable nvm interrupt (optional). 3. write the key sequence to nvmkey. 4. set the wr bit to begin erase cycle. 5. either poll the wr bit or wait for the nvm interrupt (nvmif is set). a typical bulk erase sequence is provided in example 6-3 . 6.4.2 single-word write to write a single word in the data eeprom, the following sequence must be followed: 1. erase one data eeprom word (as mentioned in section 6.4.1, erase data eeprom ) if pgmonly bit (nvmcon<12>) is set to ? 1 ?. 2. write the data word into the data eeprom latch. 3. program the data word into the eeprom: - configure the nvmcon register to program one eeprom word (nvmcon<5:0> = 0001xx ). - clear nvmif status bit and enable nvm interrupt (optional). - write the key sequence to nvmkey. - set the wr bit to begin erase cycle. - either poll the wr bit or wait for the nvm interrupt (nvmif set). - to get cleared, wait until nvmif is set. a typical single-word write sequence is provided in example 6-4 . example 6-3: data eeprom bulk erase example 6-4: single-word write to data eeprom // set up nvmcon to bulk erase the data eeprom nvmcon = 0x4050; // disable interrupts for 5 instructions asm volatile ("disi #5"); // issue unlock sequence and start erase cycle __builtin_write_nvm(); int __attribute__ ((space(eedata))) eedata = 0x1234; // global variable located in eeprom int newdata; // new data to write to eeprom unsigned int offset; // set up nvmcon to erase one word of data eeprom nvmcon = 0x4004; // set up a pointer to the eeprom location to be erased tblpag = __builtin_tblpage(&eedata); // initialize ee data page pointer offset = __builtin_tbloffset(&eedata); // initizlize lower word of address __builtin_tblwtl(offset, newdata); // write eeprom data to write latch asm volatile ("disi #5"); // disable interrupts for 5 instructions __builtin_write_nvm(); // issue unlock sequence & start write cycle while(nvmconbits.wr=1); // optional: poll wr bit to wait for // write sequence to complete
pic24f16kl402 family ds31037b-page 58 ? 2011 microchip technology inc. 6.4.3 reading the data eeprom to read a word from data eeprom, the table read instruction is used. since the eeprom array is only 16 bits wide, only the tblrdl instruction is needed. the read operation is performed by loading tblpag and wreg with the address of the eeprom location followed by a tblrdl instruction. a typical read sequence, using the table pointer management ( builtin_tblpage and builtin_tbloffset ) and table read ( builtin_tblrdl ) procedures from the c30 compiler library, is provided in example 6-5 . program space visibility (psv) can also be used to read locations in the data eeprom. example 6-5: reading the data eeprom using the tblrd command int __attribute__ ((space(eedata))) eedata = 0x1234; // global variable located in eeprom int data; // data read from eeprom unsigned int offset; // set up a pointer to the eeprom location to be erased tblpag = __builtin_tblpage(&eedata); // initialize ee data page pointer offset = __builtin_tbloffset(&eedata); // initizlize lower word of address data = __builtin_tblrdl(offset); // write eeprom data to write latch
? 2011 microchip technology inc. ds31037b-page 59 pic24f16kl402 family 7.0 resets the reset module combines all reset sources and controls the device master reset signal, sysrst . the following is a list of device reset sources: ? por: power-on reset ?mclr : pin reset ?swr: reset instruction ? wdtr: watchdog timer reset ? bor: brown-out reset ? trapr: trap conflict reset ? iopuwr: illegal opcode reset ? uwr: uninitialized w register reset a simplified block diagram of the reset module is shown in figure 7-1 . any active source of reset will make the sysrst signal active. many registers associated with the cpu and peripherals are forced to a known reset state. most registers are unaffected by a reset; their status is unknown on power-on reset (por) and unchanged by all other resets. all types of device reset will set a corresponding status bit in the rcon register to indicate the type of reset (see register 7-1 ). a por will clear all bits except for the bor and por bits (rcon<1:0>) which are set. the user may set or clear any bit at any time during code execution. the rcon bits only serve as status bits. setting a particular reset status bit in software will not cause a device reset to occur. the rcon register also has other bits associated with the watchdog timer (wdt) and device power-saving states. the function of these bits is discussed in other sections of this manual. figure 7-1: reset sy stem block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on resets, refer to the ?pic24f family reference manual? , section 40. ?reset with programmable brown-out reset? (ds39728). note: refer to the specific peripheral or cpu section of this manual for register reset states. note: the status bits in the rcon register should be cleared after they are read so that the next rcon register value, after a device reset, will be meaningful. mclr v dd v dd rise detect por sleep or idle brown-out reset reset instruction wdt module glitch filter bor trap conflict illegal opcode uninitialized w register sysrst boren<1:0> 00 01 10 11 0 sboren sleep 1 configuration mismatch
pic24f16kl402 family ds31037b-page 60 ? 2011 microchip technology inc. register 7-1: rcon: re set control register ( 1 ) r/w-0 r/w-0 r/w-0 ( 3 ) u-0 u-0 u-0 r/w-0 r/w-0 trapr iopuwr sboren ? ? ?cmpmslp bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 r/w-1 extr swr swdten ( 2 ) wdto sleep idle bor por bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 trapr: trap reset flag bit 1 = a trap conflict reset has occurred 0 = a trap conflict reset has not occurred bit 14 iopuwr: illegal opcode or uninitialized w access reset flag bit 1 = an illegal opcode detection, an illegal address mode or an uninitialized w register is used as an address pointer and caused a reset 0 = an illegal opcode or uninitialized w reset has not occurred bit 13 sboren: software enable/disable of bor bit ( 3 ) 1 = bor is turned on in software 0 = bor is turned off in software bit 12-10 unimplemented: read as ? 0 ? bit 9 cm: configuration word mismatch reset flag bit 1 = a configuration word mismatch reset has occurred 0 = a configuration word mismatch reset has not occurred bit 8 pmslp: program memory power during sleep bit 1 = program memory bias voltage remains powered during sleep 0 = program memory bias voltage is powered down during sleep bit 7 extr: external reset (mclr ) pin bit 1 = a master clear (pin) reset has occurred 0 = a master clear (pin) reset has not occurred bit 6 swr: software reset (instruction) flag bit 1 = a reset instruction has been executed 0 = a reset instruction has not been executed bit 5 swdten: software enable/disable of wdt bit ( 2 ) 1 = wdt is enabled 0 = wdt is disabled bit 4 wdto: watchdog timer time-out flag bit 1 = wdt time-out has occurred 0 = wdt time-out has not occurred note 1: all of the reset status bits may be set or cleared in software. setting one of these bits in software does not cause a device reset. 2: if the fwdten configuration bit is ? 1 ? (unprogrammed), the wdt is always enabled, regardless of the swdten bit setting. 3: the sboren bit is forced to ? 0 ? when disabled by the configuration bits, boren<1:0> (fpor<1:0>). when the configuration bits are set to enable sboren, the default reset state will be ? 1 ?.
? 2011 microchip technology inc. ds31037b-page 61 pic24f16kl402 family table 7-1: reset flag bit operation 7.1 clock source selection at reset if clock switching is enabled, the system clock source at device reset is chosen, as shown in table 7-2 . if clock switching is disabled, the system clock source is always selected according to the oscillator configuration bits. for more information, see section 9.0 ?oscillator configuration? . table 7-2: oscillator selection vs. type of reset (clock switching enabled) bit 3 sleep: wake-up from sleep flag bit 1 = device has been in sleep mode 0 = device has not been in sleep mode bit 2 idle: wake-up from idle flag bit 1 = device has been in idle mode 0 = device has not been in idle mode bit 1 bor: brown-out reset flag bit 1 = a brown-out reset has occurred (the bor is also set after a por) 0 = a brown-out reset has not occurred bit 0 por: power-on reset flag bit 1 = a power-up reset has occurred 0 = a power-up reset has not occurred flag bit setting event clearing event trapr (rcon<15>) trap conflict event por iopuwr (rcon<14>) illegal opcode or uninitialized w register access por cm (rcon<9>) configuration mismatch reset por extr (rcon<7>) mclr reset por swr (rcon<6>) reset instruction por wdto (rcon<4>) wdt time-out pwrsav instruction, por sleep (rcon<3>) pwrsav #sleep instruction por idle (rcon<2>) pwrsav #idle instruction por bor (rcon<1>) por, bor ? por (rcon<0>) por ? note: all reset flag bits may be set or cleared by the user software. register 7-1: rcon: re set control register ( 1 ) (continued) note 1: all of the reset status bits may be set or cleared in software. setting one of these bits in software does not cause a device reset. 2: if the fwdten configuration bit is ? 1 ? (unprogrammed), the wdt is always enabled, regardless of the swdten bit setting. 3: the sboren bit is forced to ? 0 ? when disabled by the configuration bits, boren<1:0> (fpor<1:0>). when the configuration bits are set to enable sboren, the default reset state will be ? 1 ?. reset type clock source determinant por fnosc configuration bits (fnosc<10:8>) bor mclr cosc control bits (osccon<14:12>) wdto swr
pic24f16kl402 family ds31037b-page 62 ? 2011 microchip technology inc. 7.2 device reset times the reset times for various types of device reset are summarized in ta b l e 7 - 3 . note that the system reset signal, sysrst , is released after the por and pwrt delay times expire. the time at which the device actually begins to execute code will also depend on the system oscillator delays, which include the oscillator start-up timer (ost) and the pll lock time. the ost and pll lock times occur in parallel with the applicable sysrst delay times. the fscm delay determines the time at which the fscm begins to monitor the system clock source after the sysrst signal is released. table 7-3: reset delay times for various device resets reset type clock source sysrst delay system clock delay notes por ( 6 ) ec t por + t pwrt ? 1 , 2 frc, frcdiv t por + t pwrt t frc 1 , 2 , 3 lprc t por + t pwrt t lprc 1 , 2 , 3 ecpll t por + t pwrt t lock 1 , 2 , 4 frcpll t por + t pwrt t frc + t lock 1 , 2 , 3 , 4 xt, hs, sosc t por + t pwrt t ost 1 , 2 , 5 xtpll, hspll t por + t pwrt t ost + t lock 1 , 2 , 4 , 5 bor ec t pwrt ? 2 frc, frcdiv t pwrt t frc 2 , 3 lprc t pwrt t lprc 2 , 3 ecpll t pwrt t lock 2 , 4 frcpll t pwrt t frc + t lock 2 , 3 , 4 xt, hs, sosc t pwrt t ost 2 , 5 xtpll, hspll t pwrt t frc + t lock 2 , 3 , 4 all others any clock ? ? none note 1: t por = power-on reset delay. 2: t pwrt = 64 ms nominal if the power-up timer is enabled; otherwise, it is zero. 3: t frc and t lprc = rc oscillator start-up times. 4: t lock = pll lock time. 5: t ost = oscillator start-up timer (ost). a 10-bit counter waits 1024 oscillator periods before releasing the oscillator clock to the system. 6: if two-speed start-up is enabled, regardless of the primary oscillator selected, the device starts with frc, and in such cases, frc start-up time is valid. note: for detailed operating frequency and timing specifications, see section 26.0 ?electrical characteristics? .
? 2011 microchip technology inc. ds31037b-page 63 pic24f16kl402 family 7.2.1 por and long oscillator start-up times the oscillator start-up circuitry and its associated delay timers are not linked to the device reset delays that occur at power-up. some crystal circuits (especially low-frequency crystals) will have a relatively long start-up time. therefore, one or more of the following conditions is possible after sysrst is released: ? the oscillator circuit has not begun to oscillate. ? the oscillator start-up timer (ost) has not expired (if a crystal oscillator is used). ? the pll has not achieved a lock (if pll is used). the device will not begin to execute code until a valid clock source has been released to the system. therefore, the oscillator and pll start-up delays must be considered when the reset delay time must be known. 7.2.2 fail-safe clock monitor (fscm) and device resets if the fscm is enabled, it will begin to monitor the system clock source when sysrst is released. if a valid clock source is not available at this time, the device will automatically switch to the frc oscillator and the user can switch to the desired crystal oscillator in the trap service routine (tsr). 7.3 special function register reset states most of the special function registers (sfrs) associated with the pic24f cpu and peripherals are reset to a particular value at a device reset. the sfrs are grouped by their peripheral or cpu function and their reset values are specified in each section of this manual. the reset value for each sfr does not depend on the type of reset, with the exception of four registers. the reset value for the reset control register, rcon, will depend on the type of device reset. the reset value for the oscillator control register, osccon, will depend on the type of reset and the programmed values of the fnosc bits in the flash configuration word (foscsel); see table 7-2 . the rcfgcal and nvmcon registers are only affected by a por. 7.4 brown-out reset (bor) pic24f16kl402 family devices implement a bor circuit, which provides the user several configuration and power-saving options. the bor is controlled by the borv<1:0> and boren<1:0> configuration bits (fpor<6:5,1:0>). there are a total of four bor configurations, which are provided in tab l e 7 - 3 . the bor threshold is set by the borv<1:0> bits. if bor is enabled (any values of boren<1:0>, except ? 00 ?), any drop of v dd below the set threshold point will reset the device. the chip will remain in bor until v dd rises above the threshold. if the power-up timer is enabled, it will be invoked after v dd rises above the threshold. then, it will keep the chip in reset for an additional time delay, t pwrt , if v dd drops below the threshold while the power-up timer is running. the chip goes back into a bor and the power-up timer will be initialized. once v dd rises above the threshold, the power-up timer will execute the additional time delay. bor and the power-up timer (pwrt) are indepen- dently configured. enabling the bor reset does not automatically enable the pwrt. 7.4.1 software enabled bor when boren<1:0> = 01 , the bor can be enabled or disabled by the user in software. this is done with the control bit, sboren (rcon<13>). setting sboren enables the bor to function, as previously described. clearing the sboren disables the bor entirely. the sboren bit only operates in this mode; otherwise, it is read as ? 0 ?. placing bor under software control gives the user the additional flexibility of tailoring the application to its environment without having to reprogram the device to change the bor configuration. it also allows the user to tailor the incremental current that the bor consumes. while the bor current is typically very small, it may have some impact in low-power applications. note: even when the bor is under software control, the bor reset voltage level is still set by the borv<1:0> configuration bits; it can not be changed in software.
pic24f16kl402 family ds31037b-page 64 ? 2011 microchip technology inc. 7.4.2 detecting bor when bor is enabled, the bor bit (rcon<1>) is always reset to ? 1 ? on any bor or por event. this makes it difficult to determine if a bor event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor. this assumes that the por and bor bits are reset to ? 0 ? in the software, immediately after any por event. if the bor bit is ? 1 ? while por is ? 0 ?, it can be reliably assumed that a bor event has occurred. 7.4.3 disabling bor in sleep mode when boren<1:0> = 10 , bor remains under hardware control and operates as previously described. however, whenever the device enters sleep mode, bor is automatically disabled. when the device returns to any other operating mode, bor is automatically re-enabled. this mode allows for applications to recover from brown-out situations, while actively executing code when the device requires bor protection the most. at the same time, it saves additional power in sleep mode by eliminating the small incremental bor current. note: even when the device exits from deep sleep mode, both the por and bor are set.
? 2011 microchip technology inc. ds31037b-page 65 pic24f16kl402 family 8.0 interrupt controller the pic24f interrupt controller reduces the numerous peripheral interrupt request signals to a single interrupt request signal to the cpu. it has the following features: ? up to eight processor exceptions and software traps ? seven user-selectable priority levels ? interrupt vector table (ivt) with up to 118 vectors ? unique vector for each interrupt or exception source ? fixed priority within a specified user priority level ? alternate interrupt vector table (aivt) for debug support ? fixed interrupt entry and return latencies 8.1 interrupt vector table (ivt) the ivt is shown in figure 8-1 . the ivt resides in the program memory, starting at location, 000004h. the ivt contains 126 vectors, consisting of eight non-maskable trap vectors, plus up to 118 sources of interrupt. in general, each interrupt source has its own vector. each interrupt vector contains a 24-bit wide address. the value programmed into each interrupt vector location is the starting address of the associated interrupt service routine (isr). interrupt vectors are prioritized in terms of their natural priority; this is linked to their position in the vector table. all other things being equal, lower addresses have a higher natural priority. for example, the interrupt associated with vector 0 will take priority over interrupts at any other vector address. pic24f16kl402 family devices implement 32 non-maskable traps and unique interrupts; these are summarized in ta b l e 8 - 1 and tab l e 8 - 2 . 8.1.1 alternate interrupt vector ta b l e (a i v t ) the alternate interrupt vector table (aivt) is located after the ivt, as shown in figure 8-1 . access to the aivt is provided by the altivt control bit (intcon2<15>). if the altivt bit is set, all interrupt and exception processes will use the alternate vectors instead of the default vectors. the alternate vectors are organized in the same manner as the default vectors. the aivt supports emulation and debugging efforts by providing a means to switch between an application and a support environment without requiring the interrupt vectors to be reprogrammed. this feature also enables switching between applications for evaluation of different software algorithms at run time. if the aivt is not needed, the aivt should be programmed with the same addresses used in the ivt. 8.2 reset sequence a device reset is not a true exception, because the interrupt controller is not involved in the reset process. the pic24f devices clear their registers in response to a reset, which forces the program counter (pc) to zero. the microcontroller then begins program execution at location, 000000h. the user programs a goto instruction at the reset address, which redirects the program execution to the appropriate start-up routine. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the interrupt controller, refer to the ?pic24f family reference manual? , section 8. ?interrupts? (ds39707). note: any unimplemented or unused vector locations in the ivt and aivt should be programmed with the address of a default interrupt handler routine that contains a reset instruction.
pic24f16kl402 family ds31037b-page 66 ? 2011 microchip technology inc. figure 8-1: pic24f interrupt vector table reset ? goto instruction 000000h reset ? goto address 000002h reserved 000004h oscillator fail trap vector address error trap vector stack error trap vector math error trap vector reserved reserved reserved interrupt vector 0 000014h interrupt vector 1 ? ? ? interrupt vector 52 00007ch interrupt vector 53 00007eh interrupt vector 54 000080h ? ? ? interrupt vector 116 0000fch interrupt vector 117 0000feh reserved 000100h reserved 000102h reserved oscillator fail trap vector address error trap vector stack error trap vector math error trap vector reserved reserved reserved interrupt vector 0 000114h interrupt vector 1 ? ? ? interrupt vector 52 00017ch interrupt vector 53 00017eh interrupt vector 54 000180h ? ? ? interrupt vector 116 decreasing natural order priority interrupt vector table (ivt) (1) alternate interrupt vector table (aivt) (1) note 1: see table 8-2 for the interrupt vector list.
? 2011 microchip technology inc. ds31037b-page 67 pic24f16kl402 family table 8-2: implemented interrupt vectors table 8-1: trap vector details vector number ivt address aivt address trap source 0 000004h 000104h reserved 1 000006h 000106h oscillator failure 2 000008h 000108h address error 3 00000ah 00010ah stack error 4 00000ch 00010ch math error 5 00000eh 00010eh reserved 6 000010h 000110h reserved 7 000012h 000112h reserved interrupt source vector number ivt address aivt address interrupt bit locations flag enable priority adc1 conversion done 13 00002eh 00012eh ifs0<13> iec0<13> ipc3<6:4> comparator event 18 000038h 000138h ifs1<2> iec1<2> ipc4<10:8> external interrupt 0 0 000014h 000114h ifs0<0> iec0<0> ipc0<2:0> external interrupt 1 20 00003ch 00013ch ifs1<4> iec1<4> ipc5<2:0> external interrupt 2 29 00004eh 00014eh ifs1<13> iec1<13> ipc7<6:4> mssp1 bus collision event 17 000036h 000136h ifs1<1> iec1<1> ipc4<6:4> mssp1 spi or i 2 c? event 16 000034h 000134h ifs1<0> iec1<0> ipc4<2:0> mssp2 bus collision event 50 000078h 000178h ifs3<2> iec3<2> ipc12<10:8> mssp2 spi or i 2 c event 49 000076h 000176h ifs3<1> iec3<1> ipc12<6:4> input change notification 19 00003ah 00013ah ifs1<3> iec1<3> ipc4<14:12> hlvd (high/low-voltage detect) 72 0000a4h 0001a4h ifs4<8> iec4<8> ipc17<2:0> nvm (nvm write complete) 15 000032h 000132h ifs0<15> iec0<15> ipc3<14:12> ccp1/eccp1 2 000018h 000118h ifs0<2> iec0<2> ipc0<10:8> ccp2 6 000020h 000120h ifs0<6> iec0<6> ipc1<10:8> ccp3 25 000046h 000146h ifs1<9> iec1<9> ipc6<6:4> timer1 3 00001ah 00011ah ifs0<3> iec0<3> ipc0<14:12> timer2 7 000022h 000122h ifs0<7> iec0<7> ipc1<14:12> timer3 8 000024h 000124h ifs0<8> iec0<8> ipc2<2:0> timer4 27 00004ah 00014ah ifs1<11> iec1<11> ipc6<14:12> timer3 gate external count 37 00005eh 00015eh ifs2<5> iec2<5> ipc9<6:4> uart1 error 65 000096h 000196h ifs4<1> iec4<1> ipc16<6:4> uart1 receiver 11 00002ah 00012ah ifs0<11> iec0<11> ipc2<14:12> uart1 transmitter 12 00002ch 00012ch ifs0<12> iec0<12> ipc3<2:0> uart2 error 66 000098h 000198h ifs4<2> iec4<2> ipc16<10:8> uart2 receiver 30 000050h 000150h ifs1<14> iec1<14> ipc7<10:8> uart2 transmitter 31 000052h 000152h ifs1<15> iec1<15> ipc7<14:12> ulpw (ultra low-power wake-up) 80 0000b4h 0001b4h ifs5<0> iec5<0> ipc20<2:0>
pic24f16kl402 family ds31037b-page 68 ? 2011 microchip technology inc. 8.3 interrupt control and status registers depending on the particular device, the pic24f16kl402 family of devices implements up to 28 registers for the interrupt controller: ? intcon1 ? intcon2 ? ifs0 through ifs5 ? iec0 through iec5 ? ipc0 through ipc7, icp9, ipc12, icp16, icp18 and ipc20 ?inttreg global interrupt control functions are controlled from intcon1 and intcon2. intcon1 contains the interrupt nesting disable (nstdis) bit, as well as the control and status flags for the processor trap sources. the intcon2 register controls the external interrupt request signal behavior and the use of the aiv table. the ifsx registers maintain all of the interrupt request flags. each source of interrupt has a status bit, which is set by the respective peripherals or external signal, and is cleared via software. the iecx registers maintain all of the interrupt enable bits. these control bits are used to individually enable interrupts from the peripherals or external signals. the ipcx registers are used to set the interrupt priority level for each source of interrupt. each user interrupt source can be assigned to one of eight priority levels. the inttreg register contains the associated interrupt vector number and the new cpu interrupt priority level, which are latched into the vector number (vecnum<6:0>) and the interrupt level (ilr<3:0>) bit fields in the inttreg register. the new interrupt priority level is the priority of the pending interrupt. the interrupt sources are assigned to the ifsx, iecx and ipcx registers in the same sequence listed in table 8-2 . for example, the int0 (external interrupt 0) is depicted as having a vector number and a natural order priority of 0. the int0if status bit is found in ifs0<0>, the int0ie enable bit in iec0<0> and the int0ip<2:0> priority bits are in the first position of ipc0 (ipc0<2:0>). although they are not specifically part of the interrupt control hardware, two of the cpu control registers contain bits that control interrupt functionality. the alu status register (sr) contains the ipl<2:0> bits (sr<7:5>). these indicate the current cpu interrupt priority level. the user may change the current cpu priority level by writing to the ipl bits. the corcon register contains the ipl3 bit, which together with the ipl<2:0> bits, also indicates the cur- rent cpu priority level. ipl3 is a read-only bit so that the trap events cannot be masked by the user?s software. all interrupt registers are described in register 8-3 through register 8-30 , in the following sections.
? 2011 microchip technology inc. ds31037b-page 69 pic24f16kl402 family register 8-1: sr: alu status register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r-0 ? ? ? ? ? ? ? dc ( 1 ) bit 15 bit 8 r/w-0 r/w-0 r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 ipl2 ( 2 , 3 ) ipl1 ( 2 , 3 ) ipl0 ( 2 , 3 ) ra ( 1 ) n ( 1 ) ov ( 1 ) z ( 1 ) c ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 7-5 ipl<2:0>: cpu interrupt priority level status bits ( 2 , 3 ) 111 = cpu interrupt priority level is 7 (15); user interrupts disabled 110 = cpu interrupt priority level is 6 (14) 101 = cpu interrupt priority level is 5 (13) 100 = cpu interrupt priority level is 4 (12) 011 = cpu interrupt priority level is 3 (11) 010 = cpu interrupt priority level is 2 (10) 001 = cpu interrupt priority level is 1 (9) 000 = cpu interrupt priority level is 0 (8) note 1: see register 3-1 for the description of these bits, which are not dedicated to interrupt control functions. 2: the ipl bits are concatenated with the ipl3 bit (corcon<3>) to form the cpu interrupt priority level. the value in parentheses indicates the interrupt priority level if ipl3 = 1 . 3: the ipl status bits are read-only when nstdis (intcon1<15>) = 1 . note: bit 8 and bits 4 through 0 are described in section 3.0 ?cpu? .
pic24f16kl402 family ds31037b-page 70 ? 2011 microchip technology inc. register 8-2: corcon: cpu control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/c-0 r/w-0 u-0 u-0 ? ? ? ?ipl3 ( 2 ) psv ( 1 ) ? ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3 ipl3: cpu interrupt priority level status bit ( 2 ) 1 = cpu interrupt priority level is greater than 7 0 = cpu interrupt priority level is 7 or less bit 1-0 unimplemented: read as ? 0 ? note 1: see register 3-2 for the description of this bit, which is not dedicated to interrupt control functions. 2: the ipl3 bit is concatenated with the ipl<2:0> bits (sr<7:5>) to form the cpu interrupt priority level. note: bit 2 is described in section 3.0 ?cpu? .
? 2011 microchip technology inc. ds31037b-page 71 pic24f16kl402 family register 8-3: intcon1: in terrupt control register 1 r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 nstdis ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 ? ? ? matherr addrerr stkerr oscfail ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nstdis: interrupt nesting disable bit 1 = interrupt nesting is disabled 0 = interrupt nesting is enabled bit 14-5 unimplemented: read as ? 0 ? bit 4 matherr: arithmetic error trap status bit 1 = overflow trap has occurred 0 = overflow trap has not occurred bit 3 addrerr: address error trap status bit 1 = address error trap has occurred 0 = address error trap has not occurred bit 2 stkerr: stack error trap status bit 1 = stack error trap has occurred 0 = stack error trap has not occurred bit 1 oscfail: oscillator failure trap status bit 1 = oscillator failure trap has occurred 0 = oscillator failure trap has not occurred bit 0 unimplemented: read as ? 0 ?
pic24f16kl402 family ds31037b-page 72 ? 2011 microchip technology inc. register 8-4: intcon2: in terrupt control register2 r/w-0 r-0, hsc u-0 u-0 u-0 u-0 u-0 u-0 altivt disi ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 ? ? ? ? ? int2ep int1ep int0ep bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 altivt: enable alternate interrupt vector table bit 1 = use alternate interrupt vector table 0 = use standard (default) vector table bit 14 disi: disi instruction status bit 1 = disi instruction is active 0 = disi instruction is not active bit 13-3 unimplemented: read as ? 0 ? bit 2 int2ep: external interrupt 2 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge bit 1 int1ep: external interrupt 1 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge bit 0 int0ep: external interrupt 0 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge
? 2011 microchip technology inc. ds31037b-page 73 pic24f16kl402 family register 8-5: ifs0: interrupt flag status register 0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 nvmif ? ad1if u1txif u1rxif ? ?t3if bit 15 bit 8 r/w-0 r/w-0 u-0 u-0 r/w-0 r/w-0 u-0 r/w-0 t2if ccp2if ? ? t1if ccp1if ?int0if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nvmif: nvm interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 14 unimplemented: read as ? 0 ? bit 13 ad1if: a/d conversion complete interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12 u1txif: uart1 transmitter interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 11 u1rxif: uart1 receiver interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 10-9 unimplemented: read as ? 0 ? bit 8 t3if: timer3 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 7 t2if: timer2 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 6 ccp2if: capture/compare/pwm 2 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 5-4 unimplemented: read as ? 0 ? bit 3 t1if: timer1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 ccp1if: capture/compare/pwm1 interrupt flag status bit (eccp1 on pic24fxxkl40x devices) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 unimplemented: read as ? 0 ? bit 0 int0if: external interrupt 0 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
pic24f16kl402 family ds31037b-page 74 ? 2011 microchip technology inc. register 8-6: ifs1: interrupt flag status register 1 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 r/w-0 u-0 u2txif ( 1 ) u2rxif ( 1 ) int2if ?t4if ( 1 ) ? ccp3if ( 1 ) ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? int1if cnif cmif bcl1if ssp1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 u2txif: uart2 transmitter interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 14 u2rxif: uart2 receiver interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 13 int2if: external interrupt 2 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12 unimplemented: read as ? 0 ? bit 11 t4if: timer4 interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 10 unimplemented: read as ? 0 ? bit 9 ccp3if: capture/compare/pwm 3 interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 8-5 unimplemented: read as ? 0 ? bit 4 int1if: external interrupt 1 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 3 cnif: input change notification interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 cmif: comparator interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 bcl1if: mssp1 i 2 c bus collision interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 ssp1if: mssp1 spi/i 2 c event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
? 2011 microchip technology inc. ds31037b-page 75 pic24f16kl402 family register 8-7: ifs2: interrupt flag status register 2 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ? t3gif ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 unimplemented: read as ? 0 ? bit 5 t3gif: timer3 external gate interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 4-0 unimplemented: read as ? 0 ? register 8-8: ifs3: interrupt flag status register 3 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 u-0 ? ? ? ? ?bcl2if ( 1 ) ssp2if ( 1 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2 bcl2if: mssp2 i 2 c bus collision interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 ssp2if: mssp2 spi/i 2 c event interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 unimplemented: read as ? 0 ? note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
pic24f16kl402 family ds31037b-page 76 ? 2011 microchip technology inc. register 8-9: ifs4: interrupt flag status register 4 u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?hlvdif bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 u-0 ? ? ? ? ?u2erif ( 1 ) u1erif ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 hlvdif: high/low-voltage detect interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 7-3 unimplemented: read as ? 0 ? bit 2 u2erif: uart2 error interrupt flag status bit ( 1 ) 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 u1erif: uart1 error interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 unimplemented: read as ? 0 ? note 1: this bit is unimplemented on pic24fxxkl10x and pic24fxxkl20x devices. register 8-10: ifs5: interrupt flag status register 5 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?ulpwuif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-1 unimplemented: read as ? 0 ? bit 0 ulpwuif: ultra low-power wake-up interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
? 2011 microchip technology inc. ds31037b-page 77 pic24f16kl402 family register 8-11: iec0: interrupt enable control register 0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 nvmie ? ad1ie u1txie u1rxie ? ?t3ie bit 15 bit 8 r/w-0 r/w-0 u-0 u-0 r/w-0 r/w-0 u-0 r/w-0 t2ie ccp2ie ? ? t1ie ccp1ie ?int0ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nvmie: nvm interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 14 unimplemented: read as ? 0 ? bit 13 ad1ie: a/d conversion complete interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 12 u1txie: uart1 transmitter interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 11 u1rxie: uart1 receiver interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 10-9 unimplemented: read as ? 0 ? bit 8 t3ie: timer3 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 7 t2ie: timer2 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 6 ccp2ie: capture/compare/pwm 2 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 5-4 unimplemented: read as ? 0 ? bit 3 t1ie: timer1 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 2 ccp1ie: capture/compare/pwm 1 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 ic1ie: input capture channel 1 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 int0ie: external interrupt 0 enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled
pic24f16kl402 family ds31037b-page 78 ? 2011 microchip technology inc. register 8-12: iec1: interrupt enable control register 1 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 r/w-0 u-0 u2txie ( 1 ) u2rxie ( 1 ) int2ie ?t4ie ( 1 ) ? ccp3ie ( 1 ) ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? int1ie cnie cmie bcl1ie ssp1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 u2txie: uart2 transmitter interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 14 u2rxie: uart2 receiver interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 13 int2ie: external interrupt 2 enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 12 unimplemented: read as ? 0 ? bit 11 t4ie: timer4 interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 10 unimplemented: read as ? 0 ? bit 9 ccp3ie: capture/compare/pwm 3 interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 8-5 unimplemented: read as ? 0 ? bit 4 int1ie: external interrupt 1 enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 3 cnie: input change notification interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 2 cmie: comparator interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 bcl1ie: mssp1 i 2 c bus collision interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 ssp1ie: mssp1 spi/i 2 c event interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
? 2011 microchip technology inc. ds31037b-page 79 pic24f16kl402 family register 8-13: iec2: interrupt enable control register 2 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ? t3gie ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 unimplemented: read as ? 0 ? bit 5 t3gif: timer3 external gate interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 4-2 unimplemented: read as ? 0 ? register 8-14: iec3: interrupt enable control register 3 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 u-0 ? ? ? ? ?bcl2ie ( 1 ) ssp2ie ( 1 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2 bcl2ie: mssp2 i 2 c bus collision interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 ssp2if: mssp2 spi/i 2 c event interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 unimplemented: read as ? 0 ? note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
pic24f16kl402 family ds31037b-page 80 ? 2011 microchip technology inc. register 8-15: iec4: interrupt enable control register 4 u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?hlvdie bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 u-0 ? ? ? ? ?u2erie ( 1 ) u1erie ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 hlvdie: high/low-voltage detect interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 7-4 unimplemented: read as ? 0 ? bit 2 u2erie: uart2 error interrupt enable bit ( 1 ) 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 u1erie: uart1 error interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 unimplemented: read as ? 0 ? note 1: this bit is unimplemented on pic24fxxkl10x and pic24fxxkl20x devices. register 8-16: iec5: interrupt enable control register 5 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?ulpwuie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-1 unimplemented: read as ? 0 ? bit 0 ulpwuie: ultra low-power wake-up interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled
? 2011 microchip technology inc. ds31037b-page 81 pic24f16kl402 family register 8-17: ipc0: interrupt pr iority control register 0 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? t1ip2 t1ip1 t1ip0 ? ccp1ip2 ccp1ip1 ccp1ip0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? int0ip2 int0ip1 int0ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t1ip<2:0>: timer1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 ccp1ip<2:0>: capture/compare/pwm 1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7-3 unimplemented: read as ? 0 ? bit 2-0 int0ip<2:0>: external interrupt 0 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f16kl402 family ds31037b-page 82 ? 2011 microchip technology inc. register 8-18: ipc1: interrupt pr iority control register 1 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? t2ip2 t2ip1 t2ip0 ? ccp2ip2 ccp2ip1 ccp2ip0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t2ip<2:0>: timer2 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 ccp2ip<2:0>: capture/compare/pwm 2 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7-0 unimplemented: read as ? 0 ?
? 2011 microchip technology inc. ds31037b-page 83 pic24f16kl402 family register 8-19: ipc2: interrupt pr iority control register 2 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? u1rxip2 u1rxip1 u1rxip0 ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? t3ip2 t3ip1 t3ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 u1rxip<2:0>: uart1 receiver interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-3 unimplemented: read as ? 0 ? bit 2-0 t3ip<2:0>: timer3 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f16kl402 family ds31037b-page 84 ? 2011 microchip technology inc. register 8-20: ipc3: interrupt pr iority control register 3 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? nvmip2 nvmip1 nvmip0 ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? ad1ip2 ad1ip1 ad1ip0 ? u1txip2 u1txip1 u1txip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 nvmip<2:0>: nvm interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-7 unimplemented: read as ? 0 ? bit 6-4 ad1ip<2:0>: a/d conversion complete interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 u1txip<2:0>: uart1 transmitter interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2011 microchip technology inc. ds31037b-page 85 pic24f16kl402 family register 8-21: ipc4: interrupt pr iority control register 4 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? cnip2 cnip1 cnip0 ?cmip2cmip1cmip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? bcl1ip2 bcl1ip1 bcl1ip0 ? ssp1ip2 ssp1ip1 ssp1ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 cnip<2:0>: input change notification interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 cmip<2:0>: comparator interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 bcl1ip<2:0>: mssp1 i 2 c bus collision interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 ssp1ip<2:0>: mssp1 spi/i 2 c event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f16kl402 family ds31037b-page 86 ? 2011 microchip technology inc. register 8-22: ipc5: interrupt pr iority control register 5 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? int1ip2 int1ip1 int1ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2-0 int1ip<2:0>: external interrupt 1 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2011 microchip technology inc. ds31037b-page 87 pic24f16kl402 family register 8-23: ipc6: interrupt pr iority control register 6 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ?t4ip2 ( 1 ) t4ip1 ( 1 ) t4ip0 ( 1 ) ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? ccp3ip2 ( 1 ) ccp3ip1 ( 1 ) ccp3ip0 ( 1 ) ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t4ip<2:0>: timer4 interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-7 unimplemented: read as ? 0 ? bit 6-4 ccp3ip: capture/compare/pwm 2 interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ? note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
pic24f16kl402 family ds31037b-page 88 ? 2011 microchip technology inc. register 8-24: ipc7: interrupt pr iority control register 7 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? u2txip2 ( 1 ) u2txip1 ( 1 ) u2txip0 ( 1 ) ? u2rxip2 ( 1 ) u2rxip1 ( 1 ) u2rxip0 ( 1 ) bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? int2ip2 int2ip1 int2ip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 u2txip<2:0>: uart2 transmitter interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 u2rxip<2:0>: uart2 receiver interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 int2ip<2:0>: external interrupt 2 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ? note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
? 2011 microchip technology inc. ds31037b-page 89 pic24f16kl402 family register 8-25: ipc9: interrupt pr iority control register 9 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? t3gip2 t3gip1 t3gip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-4 t3gip<2:0>: timer3 external gate interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
pic24f16kl402 family ds31037b-page 90 ? 2011 microchip technology inc. register 8-26: ipc12: interrupt priority control register 12 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? bcl2ip2 ( 1 ) bcl2ip1 ( 1 ) bcl2ip0 ( 1 ) bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? ssp2ip2 ( 1 ) ssp2ip1 ( 1 ) ssp2ip0 ( 1 ) ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-11 unimplemented: read as ? 0 ? bit 10-8 bcl2ip<2:0>: mssp2 i 2 c? bus collision interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 ssp2ip<2:0>: mssp2 spi/i 2 c event interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ? note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
? 2011 microchip technology inc. ds31037b-page 91 pic24f16kl402 family register 8-27: ipc16: interrupt priority control register 16 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ?u2erip2 ( 1 ) u2erip1 ( 1 ) u2erip0 ( 1 ) bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ?u1erip2 ( 1 ) u1erip1 ( 1 ) u1erip0 ( 1 ) ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-11 unimplemented: read as ? 0 ? bit 10-8 u2erip<2:0>: uart2 error interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 u1erip<2:0>: uart1 error interrupt priority bits ( 1 ) 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ? note 1: these bits are unimplemented on pic24fxxkl10x and pic24fxxkl20x devices.
pic24f16kl402 family ds31037b-page 92 ? 2011 microchip technology inc. register 8-28: ipc18: interrupt priority control register 18 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? hlvdip2 hlvdip1 hlvdip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2-0 hlvdip<2:0>: high/low-voltage detect interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled register 8-29: ipc20: interrupt priority control register 20 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? ulpwuip2 ulpwuip1 ulpwuip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 6-4 ulpwuip<2:0>: ultra low-power wake-up interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2011 microchip technology inc. ds31037b-page 93 pic24f16kl402 family register 8-30: inttreg: interrupt control and status register r-0 r-0 r/w-0 u-0 r-0 r-0 r-0 r-0 cpuirq ?vhold ? ilr3 ilr2 ilr1 ilr0 bit 15 bit 8 u-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 ? vecnum6 vecnum5 vecnum4 vecnum3 vecnum2 vecnum1 vecnum0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 cpuirq: interrupt request from interrupt controller cpu bit 1 = an interrupt request has occurred but has not yet been acknowledged by the cpu (this will happen when the cpu priority is higher than the interrupt priority) 0 = no interrupt request is left unacknowledged bit 14 reserved: maintain as ? 0 ? bit 13 vhold: vector hold bit allows vector number capture and changes what interrupt is stored in the vecnum bit. 1 = vecnum will contain the value of the highest priority pending interrupt, instead of the current interrupt 0 = vecnum will contain the value of the last acknowledged interrupt (last interrupt that has occurred with higher priority than the cpu, even if other interrupts are pending) bit 12 unimplemented: read as ? 0 ? bit 11-8 ilr<3:0>: new cpu interrupt priority level bits 1111 = cpu interrupt priority level is 15 ? ? ? 0001 = cpu interrupt priority level is 1 0000 = cpu interrupt priority level is 0 bit 7 unimplemented: read as ? 0 ? bit 6-0 vecnum<6:0>: vector number of pending interrupt bits 0111111 = interrupt vector pending is number 135 ? ? ? 0000001 = interrupt vector pending is number 9 0000000 = interrupt vector pending is number 8
pic24f16kl402 family ds31037b-page 94 ? 2011 microchip technology inc. 8.4 interrupt setup procedures 8.4.1 initialization to configure an interrupt source: 1. set the nstdis control bit (intcon1<15>) if nested interrupts are not desired. 2. select the user-assigned priority level for the interrupt source by writing the control bits in the appropriate ipcx register. the priority level will depend on the specific application and the type of interrupt source. if multiple priority levels are not desired, the ipcx register control bits, for all enabled interrupt sources, may be programmed to the same non-zero value. 3. clear the interrupt flag status bit associated with the peripheral in the associated ifsx register. 4. enable the interrupt source by setting the interrupt enable control bit associated with the source in the appropriate iecx register. 8.4.2 interrupt service routine the method that is used to declare an isr and initialize the ivt with the correct vector address depends on the programming language (i.e., c or assembler) and the language development toolsuite that is used to develop the application. in general, the user must clear the interrupt flag in the appropriate ifsx register for the source of the interrupt that the isr handles. otherwise, the isr will be re-entered immediately after exiting the routine. if the isr is coded in assembly language, it must be terminated using a retfie instruction to unstack the saved pc value, srl value and old cpu priority level. 8.4.3 trap service routine (tsr) a trap service routine (tsr) is coded like an isr, except that the appropriate trap status flag in the intcon1 register must be cleared to avoid re-entry into the tsr. 8.4.4 interrupt disable all user interrupts can be disabled using the following procedure: 1. push the current sr value onto the software stack using the push instruction. 2. force the cpu to priority level 7 by inclusive oring the value, oeh with srl. to enable user interrupts, the pop instruction may be used to restore the previous sr value. only user interrupts with a priority level of 7 or less can be disabled. trap sources (level 8-15) cannot be disabled. the disi instruction provides a convenient way to disable interrupts of priority levels 1-6 for a fixed period. level 7 interrupt sources are not disabled by the disi instruction. note: at a device reset, the ipcx registers are initialized, such that all user interrupt sources are assigned to priority level 4.
? 2011 microchip technology inc. ds31037b-page 95 pic24f16kl402 family 9.0 oscillator configuration the oscillator system for the pic24f16kl402 family of devices has the following features: ? a total of five external and internal oscillator options as clock sources, providing 11 different clock modes. ? on-chip 4x phase locked loop (pll) to boost internal operating frequency on select internal and external oscillator sources. ? software-controllable switching between various clock sources. ? software-controllable postscaler for selective clocking of cpu for system power savings. ? system frequency range declaration bits for ec mode. when using an external clock source, the current consumption is reduced by setting the declaration bits to the expected frequency range. ? a fail-safe clock monitor (fscm) that detects clock failure and permits safe application recovery or shutdown. a simplified diagram of the oscillator system is shown in figure 9-1 . figure 9-1: pic24f16kl402 family clock diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on oscillator configuration, refer to the ?pic24f family reference manual? , section 38. ?oscillator with 500 khz low-power frc? (ds39726). secondary oscillator soscen enable oscillator sosco sosci clock source option for other modules osci osco primary oscillator xt, hs, ec postscaler clkdiv<10:8> wdt, pwrt, dswdt frcdiv 31 khz (nominal) 8 mhz frc lprc oscillator sosc lprc clock control logic fail-safe clock monitor frc 4 x pll xtpll, hspll ecpll,frcpll 8 mhz 4 mhz cpu peripherals postscaler clkdiv<14:12> clko reference clock generator refo refocon<15:8> oscillator 500 khz lpfrc oscillator
pic24f16kl402 family ds31037b-page 96 ? 2011 microchip technology inc. 9.1 cpu clocking scheme the system clock source can be provided by one of four sources: ? primary oscillator (posc) on the osci and osco pins ? secondary oscillator (sosc) on the sosci and sosco pins pic24f16kl402 family devices consist of two types of secondary oscillators: - high-power secondary oscillator - low-power secondary oscillator these can be selected by using the soscsel (fosc<5>) bit. ? fast internal rc (frc) oscillator - 8 mhz frc oscillator - 500 khz lower power frc oscillator ? low-power internal rc (lprc) oscillator with two modes: - high-power/high accuracy mode - low-power/low accuracy mode the primary oscillator and 8 mhz frc sources have the option of using the internal 4x pll. the frequency of the frc clock source can optionally be reduced by the pro- grammable clock divider. the selected clock source generates the processor and peripheral clock sources. the processor clock source is divided by two to produce the internal instruction cycle clock, f cy . in this document, the instruction cycle clock is also denoted by f osc /2. the internal instruction cycle clock, f osc /2, can be provided on the osco i/o pin for some operating modes of the primary oscillator. 9.2 initial configuration on por the oscillator source (and operating mode) that is used at a device power-on reset (por) event is selected using configuration bit settings. the oscillator configuration bit settings are located in the configuration registers in the program memory (for more information, see section 23.1 ?configuration bits? ). the primary oscillator configuration bits, poscmd<1:0> (fosc<1:0>), and the initial oscillator select configuration bits, fnosc<2:0> (foscsel<2:0>), select the oscillator source that is used at a por. the frc primary oscillator with postscaler (frcdiv) is the default (unprogrammed) selection. the secondary oscillator, or one of the internal oscillators, may be chosen by programming these bit locations. the ec mode frequency range configuration bits, poscfreq<1:0> (fosc<4:3>), optimize power consumption when running in ec mode. the default configuration is ?frequency range is greater than 8 mhz?. the configuration bits allow users to choose between the various clock modes, shown in tab l e 9 - 1 . 9.2.1 clock switching mode configuration bits the fcksm configuration bits (fosc<7:6>) are used jointly to configure device clock switching and the fscm. clock switching is enabled only when fcksm1 is programmed (? 0 ?). the fscm is enabled only when fcksm<1:0> are both programmed (? 00 ?). table 9-1: configuration bit va lues for clock selection oscillator mode oscillator source poscmd<1:0> fnosc<2:0> notes 8 mhz frc oscillator with postscaler (frcdiv) internal 11 111 1 , 2 500 khz frc oscillator with postscaler (lpfrcdiv) internal 11 110 1 low-power rc oscillator (lprc) internal 11 101 1 secondary (timer1) oscillator (sosc) secondary 00 100 1 primary oscillator (hs) with pll module (hspll) primary 10 011 primary oscillator (ec) with pll module (ecpll) primary 00 011 primary oscillator (hs) primary 10 010 primary oscillator (xt) primary 01 010 primary oscillator (ec) primary 00 010 8 mhz frc oscillator with pll module (frcpll) internal 11 001 1 8 mhz frc oscillator (frc) internal 11 000 1 note 1: osco pin function is determined by the osciofnc configuration bit. 2: this is the default oscillator mode for an unprogrammed (erased) device.
? 2011 microchip technology inc. ds31037b-page 97 pic24f16kl402 family 9.3 control registers the operation of the oscillator is controlled by three special function registers (sfrs): ? osccon ?clkdiv ?osctun the osccon register ( register 9-1 ) is the main control register for the oscillator. it controls clock source switching and allows the monitoring of clock sources. the clock divider register ( register 9-2 ) controls the features associated with doze mode, as well as the postscaler for the frc oscillator. the frc oscillator tune register ( register 9-3 ) allows the user to fine tune the frc oscillator. osctun functionality has been provided to help customers com- pensate for temperature effects on the frc frequency over a wide range of temperatures. the tuning step size is an approximation and is neither characterized nor tested. register 9-1: osccon: os cillator control register u-0 r-0, hsc r-0, hsc r-0, hsc u-0 r/w-x ( 1 ) r/w-x ( 1 ) r/w-x ( 1 ) ? cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 bit 15 bit 8 r/so-0, hsc u-0 r-0, hsc ( 2 ) u-0 r/co-0, hs r/w-0 ( 3 ) r/w-0 r/w-0 clklock ?lock ? cf soscdrv soscen oswen bit 7 bit 0 legend: hsc = hardware settable/clearable bit hs = hardware settable bit co = clearable only bit so = settable only bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 cosc<2:0>: current oscillator selection bits 111 = 8 mhz fast rc oscillator with postscaler (frcdiv) 110 = 500 khz low-power fast rc oscillator (frc) with postscaler (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (xtpll, hspll, ecpll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with postscaler and pll module (frcpll) 000 = 8 mhz frc oscillator (frc) bit 11 unimplemented: read as ? 0 ? bit 10-8 nosc<2:0>: new oscillator selection bits ( 1 ) 111 = 8 mhz fast rc oscillator with postscaler (frcdiv) 110 = 500 khz low-power fast rc oscillator (frc) with postscaler (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (xtpll, hspll, ecpll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with postscaler and pll module (frcpll) 000 = 8 mhz frc oscillator (frc) note 1: reset values for these bits are determined by the fnosc configuration bits. 2: also resets to ? 0 ? during any valid clock switch or whenever a non-pll clock mode is selected. 3: when sosc is selected to run from a digital clock input, rather than an external crystal (soscsrc = 0 ), this bit has no effect.
pic24f16kl402 family ds31037b-page 98 ? 2011 microchip technology inc. bit 7 clklock: clock selection lock enabled bit if fscm is enabled (fcksm1 = 1 ): 1 = clock and pll selections are locked 0 = clock and pll selections are not locked and may be modified by setting the oswen bit if fscm is disabled (fcksm1 = 0 ): clock and pll selections are never locked and may be modified by setting the oswen bit. bit 6 unimplemented: read as ? 0 ? bit 5 lock: pll lock status bit ( 2 ) 1 = pll module is in lock or the pll module start-up timer is satisfied 0 = pll module is out of lock, the pll start-up timer is running or pll is disabled bit 4 unimplemented: read as ? 0 ? bit 3 cf: clock fail detect bit 1 = fscm has detected a clock failure 0 = no clock failure has been detected bit 2 soscdrv : secondary oscillator drive strength bit ( 3 ) 1 = high-power sosc circuit is selected 0 = low/high-power select is done via the soscsrc configuration bit bit 1 soscen: 32 khz secondary oscillator (sosc) enable bit 1 = enable secondary oscillator 0 = disable secondary oscillator bit 0 oswen: oscillator switch enable bit 1 = initiate an oscillator switch to the clock source specified by the nosc<2:0> bits 0 = oscillator switch is complete register 9-1: osccon: oscillato r control register (continued) note 1: reset values for these bits are determined by the fnosc configuration bits. 2: also resets to ? 0 ? during any valid clock switch or whenever a non-pll clock mode is selected. 3: when sosc is selected to run from a digital clock input, rather than an external crystal (soscsrc = 0 ), this bit has no effect.
? 2011 microchip technology inc. ds31037b-page 99 pic24f16kl402 family register 9-2: clkdiv: clock divider register r/w-0 r/w-0 r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 roi doze2 doze1 doze0 dozen ( 1 ) rcdiv2 rcdiv1 rcdiv0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 roi: recover on interrupt bit 1 = interrupts clear the dozen bit, and reset the cpu and peripheral clock ratio to 1:1 0 = interrupts have no effect on the dozen bit bit 14-12 doze<2:0>: cpu-to-peripheral clock ratio select bits 111 = 1:128 110 = 1:64 101 = 1:32 100 = 1:16 011 = 1:8 010 = 1:4 001 = 1:2 000 = 1:1 bit 11 dozen: doze enable bit ( 1 ) 1 = doze<2:0> bits specify the cpu-to-peripheral clock ratio 0 = cpu and the peripheral clock ratio are set to 1:1 bit 10-8 rcdiv<2:0>: frc postscaler select bits when osccon (cosc<2:0>) = 111 or 001 : 111 = 31.25 khz (divide by 256) 110 = 125 khz (divide by 64) 101 = 250 khz (divide by 32) 100 = 500 khz (divide by 16) 011 = 1 mhz (divide by 8) 010 = 2 mhz (divide by 4) 001 = 4 mhz (divide by 2) (default) 000 = 8 mhz (divide by 1) when osccon (cosc<2:0>) = 110 : 111 = 1.95 khz (divide by 256) 110 = 7.81 khz (divide by 64) 101 = 15.62 khz (divide by 32) 100 = 31.25 khz (divide by 16) 011 = 62.5 khz (divide by 8) 010 = 125 khz (divide by 4) 001 = 250 khz (divide by 2) (default) 000 = 500 khz (divide by 1) bit 7-0 unimplemented: read as ? 0 ? note 1: this bit is automatically cleared when the roi bit is set and an interrupt occurs.
pic24f16kl402 family ds31037b-page 100 ? 2011 microchip technology inc. register 9-3: osctun: frc oscillator tune register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? tun5 ( 1 ) tun4 ( 1 ) tun3 ( 1 ) tun2 ( 1 ) tun1 ( 1 ) tun0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 unimplemented: read as ? 0 ? bit 5-0 tun<5:0>: frc oscillator tuning bits ( 1 ) 011111 = maximum frequency deviation 011110 ? ? ? 000001 000000 = center frequency, oscillator is running at factory calibrated frequency 111111 ? ? ? 100001 100000 = minimum frequency deviation note 1: increments or decrements of tun<5:0> may not change the frc frequency in equal steps over the frc tuning range and may not be monotonic.
? 2011 microchip technology inc. ds31037b-page 101 pic24f16kl402 family 9.4 clock switching operation with few limitations, applications are free to switch between any of the four clock sources (posc, sosc, frc and lprc) under software control and at any time. to limit the possible side effects that could result from this flexibility, pic24f devices have a safeguard lock built into the switching process. 9.4.1 enabling clock switching to enable clock switching, the fcksm1 configuration bit in the fosc configuration register must be programmed to ? 0 ?. (refer to section 23.0 ?special features? for further details.) if the fcksm1 configuration bit is unprogrammed (? 1 ?), the clock switching function and fscm function are disabled; this is the default setting. the noscx control bits (osccon<10:8>) do not control the clock selection when clock switching is disabled. however, the coscx bits (osccon<14:12>) will reflect the clock source selected by the fnoscx configuration bits. the oswen control bit (osccon<0>) has no effect when clock switching is disabled; it is held at ? 0 ? at all times. 9.4.2 oscillator switching sequence at a minimum, performing a clock switch requires this basic sequence: 1. if desired, read the coscx bits (osccon<14:12>) to determine the current oscillator source. 2. perform the unlock sequence to allow a write to the osccon register high byte. 3. write the appropriate value to the noscx bits (osccon<10:8>) for the new oscillator source. 4. perform the unlock sequence to allow a write to the osccon register low byte. 5. set the oswen bit to initiate the oscillator switch. once the basic sequence is completed, the system clock hardware responds automatically, as follows: 1. the clock switching hardware compares the coscx bits with the new value of the noscx bits. if they are the same, then the clock switch is a redundant operation. in this case, the oswen bit is cleared automatically and the clock switch is aborted. 2. if a valid clock switch has been initiated, the lock (osccon<5>) and cf (osccon<3>) bits are cleared. 3. the new oscillator is turned on by the hardware if it is not currently running. if a crystal oscillator must be turned on, the hardware will wait until the ost expires. if the new source is using the pll, then the hardware waits until a pll lock is detected (lock = 1 ). 4. the hardware waits for 10 clock cycles from the new clock source and then performs the clock switch. 5. the hardware clears the oswen bit to indicate a successful clock transition. in addition, the noscx bits value is transferred to the coscx bits. 6. the old clock source is turned off at this time, with the exception of lprc (if wdt, fscm or rtcc with lprc as a clock source are enabled) or sosc (if soscen remains enabled). note: the primary oscillator mode has three different submodes (xt, hs and ec), which are determined by the poscmdx configuration bits. while an application can switch to and from primary oscillator mode in software, it cannot switch between the different primary submodes without reprogramming the device. note 1: the processor will continue to execute code throughout the clock switching sequence. timing-sensitive code should not be executed during this time. 2: direct clock switches between any primary oscillator mode with pll and frcpll mode are not permitted. this applies to clock switches in either direction. in these instances, the application must switch to frc mode as a transition clock source between the two pll modes.
pic24f16kl402 family ds31037b-page 102 ? 2011 microchip technology inc. the following code sequence for a clock switch is recommended: 1. disable interrupts during the osccon register unlock and write sequence. 2. execute the unlock sequence for the osccon high byte by writing 78h and 9ah to osccon<15:8>, in two back-to-back instructions. 3. write the new oscillator source to the noscx bits in the instruction immediately following the unlock sequence. 4. execute the unlock sequence for the osccon low byte by writing 46h and 57h to osccon<7:0>, in two back-to-back instructions. 5. set the oswen bit in the instruction immediately following the unlock sequence. 6. continue to execute code that is not clock-sensitive (optional). 7. invoke an appropriate amount of software delay (cycle counting) to allow the selected oscillator and/or pll to start and stabilize. 8. check to see if oswen is ? 0 ?. if it is, the switch was successful. if oswen is still set, then check the lock bit to determine the cause of failure. the core sequence for unlocking the osccon register and initiating a clock switch is shown in example 9-1 . example 9-1: basic code sequence for clock switching 9.5 reference clock output in addition to the clko output (f osc /2) available in certain oscillator modes, the device clock in the pic24f16kl402 family devices can also be configured to provide a reference clock output signal to a port pin. this feature is available in all oscillator configurations and allows the user to select a greater range of clock submultiples to drive external devices in the application. this reference clock output is controlled by the refocon register ( register 9-4 ). setting the roen bit (refocon<15>) makes the clock signal available on the refo pin. the rodiv bits (refocon<11:8>) enable the selection of 16 different clock divider options. the rosslp and rosel bits (refocon<13:12>) control the availability of the reference output during sleep mode. the rosel bit determines if the oscillator on osc1 and osc2, or the current system clock source, is used for the reference clock output. the rosslp bit determines if the reference source is available on refo when the device is in sleep mode. to use the reference clock output in sleep mode, both the rosslp and rosel bits must be set. the device clock must also be configured for one of the primary modes (ec, hs or xt). therefore, if the rosel bit is also not set, the oscillator on osc1 and osc2 will be powered down when the device enters sleep mode. clearing the rosel bit allows the reference output frequency to change as the system clock changes during any clock switches. ;place the new oscillator selection in w0 ;oscconh (high byte) unlock sequence mov #oscconh, w1 mov #0x78, w2 mov #0x9a, w3 mov.b w2, [w1] mov.b w3, [w1] ;set new oscillator selection mov.b wreg, oscconh ;oscconl (low byte) unlock sequence mov #oscconl, w1 mov #0x46, w2 mov #0x57, w3 mov.b w2, [w1] mov.b w3, [w1] ;start oscillator switch operation bset osccon,#0
? 2011 microchip technology inc. ds31037b-page 103 pic24f16kl402 family register 9-4: refocon: reference oscillator control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 roen ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 roen: reference oscillator output enable bit 1 = reference oscillator enabled on refo pin 0 = reference oscillator disabled bit 14 unimplemented: read as ? 0 ? bit 13 rosslp: reference oscillator output stop in sleep bit 1 = reference oscillator continues to run in sleep 0 = reference oscillator is disabled in sleep bit 12 rosel: reference oscillator source select bit 1 = primary oscillator is used as the base clock ( 1 ) 0 = system clock is used as the base clock; the base clock reflects any clock switching of the device bit 11-8 rodiv<3:0>: reference oscillator divisor select bits 1111 = base clock value divided by 32,768 1110 = base clock value divided by 16,384 1101 = base clock value divided by 8,192 1100 = base clock value divided by 4,096 1011 = base clock value divided by 2,048 1010 = base clock value divided by 1,024 1001 = base clock value divided by 512 1000 = base clock value divided by 256 0111 = base clock value divided by 128 0110 = base clock value divided by 64 0101 = base clock value divided by 32 0100 = base clock value divided by 16 0011 = base clock value divided by 8 0010 = base clock value divided by 4 0001 = base clock value divided by 2 0000 = base clock value bit 7-0 unimplemented: read as ? 0 ? note 1: the crystal oscillator must be enabled using the fosc<2:0> bits; the crystal maintains the operation in sleep mode.
pic24f16kl402 family ds31037b-page 104 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 105 pic24f16kl402 family 10.0 power-saving features the pic24f16kl402 family of devices provides the ability to manage power consumption by selectively managing clocking to the cpu and the peripherals. in general, a lower clock frequency and a reduction in the number of circuits being clocked constitutes lower consumed power. all pic24f devices manage power consumption using several strategies: ? clock frequency ? instruction-based idle and sleep modes ? hardware-based periodic wake-up from sleep ? software controlled doze mode ? selective peripheral control in software combinations of these methods can be used to selectively tailor an application?s power consumption, while still maintaining critical application features, such as timing-sensitive communications. 10.1 clock frequency and clock switching pic24f devices allow for a wide range of clock frequencies to be selected under application control. if the system clock configurati on is not locked, users can choose low-power or high-precision oscillators by simply changing the nosc bits. the process of changing a system clock during operation, as well as limitations to the process, are discussed in more detail in section 9.0 ?oscillator configuration? . 10.2 instruction-based power-saving modes pic24f devices have two special power-saving modes that are entered through the execution of a special pwrsav instruction. sleep mode stops clock operation and halts all code execution; idle mode halts the cpu and code execution, but allows peripheral modules to continue operation. the assembly syntax of the pwrsav instruction is shown in example 10-1 . sleep and idle modes can be exited as a result of an enabled interrupt, wdt time-out or a device reset. when the device exits these modes, it is said to ?wake-up?. example 10-1: pwrsav instruction syntax note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on power-saving features, refer to the ?pic24f family reference manual? , ?section 39. power-saving features with deep sleep? (ds39727). note: sleep_mode and idle_mode are constants, defined in the assembler include file for the selected device. pwrsav #sleep_mode ; put the device into sleep mode pwrsav #idle_mode ; put the device into idle mode
pic24f16kl402 family ds31037b-page 106 ? 2011 microchip technology inc. 10.2.1 sleep mode sleep mode includes these features: ? the system clock source is shut down. if an on-chip oscillator is used, it is turned off. ? the device current consumption will be reduced to a minimum, provided that no i/o pin is sourcing current. ? the i/o pin directions and states are frozen. ? the fail-safe clock monitor does not operate during sleep mode since the system clock source is disabled. ? the lprc clock will continue to run in sleep mode if the wdt or rtcc with lprc as clock source is enabled. ? the wdt, if enabled, is automatically cleared prior to entering sleep mode. ? some device features, or peripherals, may continue to operate in sleep mode. this includes items, such as the input change notification on the i/o ports, or peripherals that use an external clock input. any peripheral that requires the system clock source for its operation will be disabled in sleep mode. the device will wake-up from sleep mode on any of these events: ? on any interrupt source that is individually enabled ? on any form of device reset ? on a wdt time-out on wake-up from sleep, the processor will restart with the same clock source that was active when sleep mode was entered. 10.2.2 idle mode idle mode has these features: ? the cpu will stop executing instructions. ? the wdt is automatically cleared. ? the system clock source remains active. by default, all peripheral modules continue to operate normally from the system clock source, but can also be selectively disabled (see section 10.5 ?selective peripheral module control? ). ? if the wdt or fscm is enabled, the lprc will also remain active. the device will wake from idle mode on any of these events: ? any interrupt that is individually enabled ? any device reset ? a wdt time-out on wake-up from idle, the clock is re-applied to the cpu. instruction execution begins immediately, start- ing with the instruction following the pwrsav instruction or the first instruction in the isr. 10.2.3 interrupts coincident with power save instructions any interrupt that coincides with the execution of a pwrsav instruction will be held off until entry into sleep or idle mode has completed. the device will then wake-up from sleep or idle mode.
? 2011 microchip technology inc. ds31037b-page 107 pic24f16kl402 family 10.3 ultra low-power wake-up the ultra low-power wake-up (ulpwu) on pin, rb0, allows a slow falling voltage to generate an interrupt without excess current consumption. this feature provides a low-power technique for periodically waking up the device from sleep mode. to use this feature: 1. charge the capacitor on rb0 by configuring the rb0 pin to an output and setting it to ? 1 ?. 2. stop charging the capacitor by configuring rb0 as an input. 3. discharge the capacitor by setting the ulpen and ulpsink bits in the ulpwcon register. 4. configure sleep mode. 5. enter sleep mode. the time-out is dependent on the discharge time of the rc circuit on rb0. when the voltage on rb0 drops below v il , the device wakes up and executes the next instruction. when the ulpwu module wakes the device from sleep mode, the ulpwuif bit (ifs5<0>) is set. soft- ware can check this bit upon wake-up to determine the wake-up source. see example 10-2 for initializing the ulpwu module. a series resistor, between rb0 and the external capacitor, provides overcurrent protection for the rb0/an0/ulpwu pin and enables software calibration of the time-out (see figure 10-1 ). figure 10-1: serial resistor a timer can be used to measure the charge time and discharge time of the capacitor. the charge time can then be adjusted to provide the desired delay in sleep. this technique compensates for the affects of temper- ature, voltage and component accuracy. the peripheral can also be configured as a simple, programmable low-voltage detect (lvd) or temperature sensor. example 10-2: ultra low-power wake-up initialization r 1 c 1 rb0 //****************************************************************************** // 1. charge the capacitor on rb0 //****************************************************************************** trisbbits.trisb0 = 0; latbbits.latb0 = 1; for(i = 0; i < 10000; i++) nop(); //****************************************************************************** //2. stop charging the capacitor on rb0 //****************************************************************************** trisbbits.trisb0 = 1; //****************************************************************************** //3. enable ulpwu interrupt //****************************************************************************** ifs5bits.ulpwuif = 0; iec5bits.ulpwuie = 1; ipc20bits.ulpwuip = 0x7; //****************************************************************************** //4. enable the ultra low power wakeup module and allow capacitor discharge //****************************************************************************** ulpwconbits.ulpen = 1; ulpwconbits.ulpsink = 1; //****************************************************************************** //5. enter sleep mode //****************************************************************************** sleep(); //for sleep, execution will resume here
pic24f16kl402 family ds31037b-page 108 ? 2011 microchip technology inc. register 10-1: ulpwcon: ulpwu control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 r/w-0 ulpen ? ulpsidl ? ? ? ? ulpsink bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ulpen: ulpwu module enable bit 1 = module is enabled 0 = module is disabled bit 14 unimplemented: read as ? 0 ? bit 13 ulpsidl: ulpwu stop in idle select bit 1 = discontinue module operation when the device enters idle mode 0 = continue module operation in idle mode bit 12-9 unimplemented: read as ? 0 ? bit 8 ulpsink: ulpwu current sink enable bit 1 = current sink is enabled 0 = current sink is disabled bit 7-0 unimplemented: read as ? 0 ?
? 2011 microchip technology inc. ds31037b-page 109 pic24f16kl402 family 10.4 doze mode generally, changing clock speed and invoking one of the power-saving modes are the preferred strategies for reducing power consumption. there may be circumstances, however, where this is not practical. for example, it may be necessary for an application to maintain uninterrupted, synchronous communication, even while it is doing nothing else. reducing system clock speed may introduce communication errors, while using a power-saving mode may stop communications completely. doze mode is a simple and effective alternative method to reduce power consumption while the device is still executing code. in this mode, the system clock continues to operate from the same source and at the same speed. peripheral modules continue to be clocked at the same speed, while the cpu clock speed is reduced. synchronization between the two clock domains is maintained, allowing the peripherals to access the sfrs while the cpu executes code at a slower rate. doze mode is enabled by setting the dozen bit (clkdiv<11>). the ratio between peripheral and core clock speed is determined by the doze<2:0> bits (clkdiv<14:12>). there are eight possible configurations, from 1:1 to 1:128, with 1:1 being the default. it is also possible to use doze mode to selectively reduce power consumption in event driven applications. this allows clock-sensitive functions, such as synchronous communications, to continue without interruption. mean- while, the cpu idles, waiting for something to invoke an interrupt routine. enabling the automatic return to full-speed cpu operation on interrupts is enabled by setting the roi bit (clkdiv<15>). by default, interrupt events have no effect on doze mode operation. 10.5 selective peripheral module control idle and doze modes allow users to substantially reduce power consumption by slowing or stopping the cpu clock. even so, peripheral modules still remain clocked and thus, consume power. there may be cases where the application needs what these modes do not provide: the allocation of power resources to cpu processing, with minimal power consumption from the peripherals. pic24f devices address this requirement by allowing peripheral modules to be selectively disabled, reducing or eliminating their power consumption. this can be done with two control bits: ? the peripheral enable bit, generically named, ?xxxen?, located in the module?s main control sfr. ? the peripheral module disable (pmd) bit, generically named, ?xxxmd?, located in one of the pmd control registers. both bits have similar functions in enabling or disabling its associated module. setting the pmd bit for a module disables all clock sources to that module, reducing its power consumption to an absolute minimum. in this state, the control and status registers associated with the peripheral will also be disabled, so writes to those registers will have no effect, and read values will be invalid. many peripheral modules have a corresponding pmd bit. in contrast, disabling a module by clearing its xxxen bit, disables its functionality, but leaves its registers available to be read and written to. power consumption is reduced, but not by as much as when the pmd bits are used. to achieve more selective power savings, peripheral modules can also be selectively disabled when the device enters idle mode. this is done through the control bit of the generic name format, ?xxxidl?. by default, all modules that can operate during idle mode will do so. using the disable on idle feature disables the module while in idle mode, allowing further reduction of power consumption during idle mode. this enhances power savings for extremely critical power applications.
pic24f16kl402 family ds31037b-page 110 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 111 pic24f16kl402 family 11.0 i/o ports all of the device pins (except v dd and v ss ) are shared between the peripherals and the parallel i/o ports. all i/o input ports feature schmitt trigger inputs for improved noise immunity. 11.1 parallel i/o (pio) ports a parallel i/o port that shares a pin with a peripheral is, in general, subservient to the peripheral. the peripheral?s output buffer data and control signals are provided to a pair of multiplexers. the multiplexers select whether the peripheral or the associated port has ownership of the output data and control signals of the i/o pin. figure 11-1 illustrates how ports are shared with other peripherals and the associated i/o pin to which they are connected. when a peripheral is enabled and the peripheral is actively driving an associated pin, the use of the pin as a general purpose output pin is disabled. the i/o pin may be read, but the output driver for the parallel port bit will be disabled. if a peripheral is enabled, but the peripheral is not actively driving a pin, that pin may be driven by a port. all port pins have three registers directly associated with their operation as digital i/o. the data direction register (trisx) determines whether the pin is an input or an output. if the data direction bit is a ? 1 ?, then the pin is an input. all port pins are defined as inputs after a reset. reads from the data latch register (latx), read the latch. writes to the data latch, write the latch. reads from the port (portx), read the port pins, while writes to the port pins, write the latch. any bit and its associated data and control registers, that are not valid for a particular device, will be dis- abled. that means the corresponding latx and trisx registers, and the port pin will read as zeros. when a pin is shared with another peripheral or func- tion that is defined as an input only, it is nevertheless, regarded as a dedicated port because there is no other competing source of outputs. figure 11-1: block diagram of a typical shared port structure note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the i/o ports, refer to the ?pic24f family reference manual? , section 12. ?i/o ports with peripheral pin select (pps)? (ds39711). note that the pic24f16kl402 family devices do not support peripheral pin select features. q d ck wr lat + tris latch i/o pin wr port data bus q d ck data latch read port read tris 1 0 1 0 wr tris peripheral output data peripheral input data i/o peripheral module peripheral output enable pio module output multiplexers output data input data peripheral module enable read lat output enable
pic24f16kl402 family ds31037b-page 112 ? 2011 microchip technology inc. 11.1.1 open-drain configuration in addition to the port, lat and tris registers for data control, each port pin can be individually configured for either digital or open-drain output. this is controlled by the open-drain control register, odcx, associated with each port. setting any of the bits configures the corresponding pin to act as an open-drain output. the maximum open-drain voltage allowed is the same as the maximum v ih specification. 11.1.2 i/o port write/read timing one instruction cycle is required between a port direction change or port write operation and a read operation of the same port. typically, this instruction would be a nop . 11.2 configuring analog port pins the use of the ans and tris registers control the operation of the a/d port pins. the port pins that are desired as analog inputs must have their corresponding tris bit set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. when reading the portx register, all pins configured as analog input channels will read as cleared (a low level). analog levels on any pin that is defined as a dig- ital input (including the anx pins) may cause the input buffer to consume current that exceeds the device specifications. 11.2.1 analog selection register i/o pins with shared analog functionality, such as a/d inputs and comparator inputs, must have their digital inputs shut off when analog functionality is used. note that analog functionality includes an analog voltage being applied to the pin externally. to allow for analog control, the ansx registers are provided. there is one ans register for each port (ansa and ansb, register 11-1 and register 11-2 ). within each ansx register, there is a bit for each pin that shares analog functionality with the digital i/o functionality. if a particular pin does not have an analog function, that bit is unimplemented.
? 2011 microchip technology inc. ds31037b-page 113 pic24f16kl402 family register 11-1: ansa: analog selection (porta) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 ? ? ? ? ansa3 ansa2 ansa1 ansa0 bit 7 bit 0 legend: u = unimplemented bit, read as ?0? r = readable bit w = writable bit hsc = hardware settable/clearable bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3-0 ansa<3:0>: analog select control bits 1 = digital input buffer is not active (use for analog input) 0 = digital input buffer is active register 11-2: ansb: analog selection (portb) r/w-1 r/w-1 r/w-1 r/w-1 u-0 u-0 u-0 u-0 ansb15 ansb14 ansb13 ( 1 ) ansb12 ( 1 ) ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ? ? ? ansb4 ansb3 ( 2 ) ansb2 ( 1 ) ansb1 ( 1 ) ansb0 ( 1 ) bit 7 bit 0 legend: u = unimplemented bit, read as ?0? r = readable bit w = writable bit hsc = hardware settable/clearable bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-12 ansb<15:12>: analog select control bits ( 1 ) 1 = digital input buffer is not active (use for analog input) 0 = digital input buffer is active bit 11-5 unimplemented: read as ? 0 ? bit 4-0 ansb<4:0>: analog select control bits ( 2 ) 1 = digital input buffer is not active (use for analog input) 0 = digital input buffer is active note 1: ansb<13:12,2:0> are unimplemented on 14-pin devices. 2: ansb<3> is unimplemented on 14-pin and 20-pin devices.
pic24f16kl402 family ds31037b-page 114 ? 2011 microchip technology inc. 11.3 input change notification the input change notification function of the i/o ports allows the pic24f16kl402 family of devices to gener- ate interrupt requests to the processor in response to a change-of-state (cos) on selected input pins. this feature is capable of detecting input change-of-states, even in sleep mode, when the clocks are disabled. depending on the device pin count, there are up to 23 external signals that may be selected (enabled) for generating an interrupt request on a change-of-state. there are six control registers associated with the cn module. the cnen1 and cnen2 registers contain the interrupt enable control bits for each of the cn input pins. setting any of these bits enables a cn interrupt for the corresponding pins. each cn pin also has a weak pull-up/pull-down connected to it. the pull-ups act as a current source that is connected to the pin. the pull-downs act as a current sink to eliminate the need for external resistors when push button or keypad devices are connected. on any pin, only the pull-up resistor or the pull-down resistor should be enabled, but not both of them. if the push button or the keypad is connected to v dd , enable the pull-down, or if they are connected to v ss , enable the pull-up resistors. the pull-ups are enabled sepa- rately using the cnpu1 and cnpu2 registers, which contain the control bits for each of the cn pins. setting any of the control bits enables the weak pull-ups for the corresponding pins. the pull-downs are enabled separately, using the cnpd1 and cnpd2 registers, which contain the control bits for each of the cn pins. setting any of the control bits enables the weak pull-downs for the corresponding pins. when the internal pull-up is selected, the pin uses v dd as the pull-up source voltage. when the internal pull-down is selected, the pins are pulled down to v ss by an internal resistor. make sure that there is no exter- nal pull-up source/pull-down sink when the internal pull-ups/pull-downs are enabled. example 11-1: port write/read example (assembly language) example 11-2: port write/read example (c language) note: pull-ups and pull-downs on change notifi- cation pins should always be disabled whenever the port pin is configured as a digital output. mov #0xff00, w0 ; configure portb<15:8> as inputs and portb<7:0> as outputs mov w0, trisb mov #0x00ff, w0 ; enable portb<15:8> digital input buffers mov w0, ansb nop ; delay 1 cycle btss portb, #13 ; next instruction trisb = 0xff00; // configure portb<15:8> as inputs and portb<7:0> as outputs ansb = 0x00ff; // enable portb<15:8> digital input buffers nop(); // delay 1 cycle if(portbbits.rb13 == 1) // execute following code if portb pin 13 is set. { }
? 2011 microchip technology inc. ds31037b-page 115 pic24f16kl402 family 12.0 timer1 the timer1 module is a 16-bit timer which can operate as a free-running, interval timer/counter, or serve as the time counter for a software-based real-time clock (rtc). timer1 is only reset on initial v dd power-on events. this allows the timer to continue operating as an rtc clock source through other types of device reset. timer1 can operate in three modes: ?16-bit timer ? 16-bit synchronous counter ? 16-bit asynchronous counter timer1 also supports these features: ? timer gate operation ? selectable prescaler settings ? timer operation during cpu idle and sleep modes ? interrupt on 16-bit period register match or falling edge of external gate signal figure 12-1 illustrates a block diagram of the 16-bit timer1 module. to configure timer1 for operation: 1. set the ton bit (= 1 ). 2. select the timer prescaler ratio using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. set or clear the tsync bit to configure synchronous or asynchronous operation. 5. load the timer period value into the pr1 register. 6. if interrupts are required, set the interrupt enable bit, t1ie. use the priority bits, t1ip<2:0>, to set the interrupt priority. figure 12-1: 16-bit time r1 module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on timers, refer to the ?pic24f family refer- ence manual? , section 14. ?timers? (ds39704). ton sync sosci sosco/ pr1 set t1if equal comparator tmr1 reset soscen 1 0 tsync q qd ck tckps<1:0> prescaler 1, 8, 64, 256 2 tgate t cy 1 0 t1ck tcs 1x 01 tgate 00 gate sync
pic24f16kl402 family ds31037b-page 116 ? 2011 microchip technology inc. register 12-1: t1con: ti mer1 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 ton ?tsidl ? ? ?t1ecs1 ( 1 ) t1ecs0 ( 1 ) bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 u-0 ? tgate tckps1 tckps0 ?tsynctcs ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer1 on bit 1 = starts 16-bit timer1 0 = stops 16-bit timer1 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-10 unimplemented: read as ? 0 ? bit 9-8 t1ecs <1:0>: timer1 extended clock select bits ( 1 ) 11 = reserved; do not use 10 = timer1 uses the lprc as the clock source 01 = timer1 uses the external clock from t1ck 00 = timer1 uses the secondary oscillator (sosc) as the clock source bit 7 unimplemented: read as ? 0 ? bit 6 tgate: timer1 gated time accumulation enable bit when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation is enabled 0 = gated time accumulation is disabled bit 5-4 tckps<1:0>: timer1 input clock prescale select bits 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3 unimplemented: read as ? 0 ? bit 2 tsync: timer1 external clock input synchronization select bit when tcs = 1 : 1 = synchronize external clock input 0 = do not synchronize external clock input when tcs = 0 : this bit is ignored. bit 1 tcs: timer1 clock source select bit 1 = timer1 clock source is selected by t1ecs<1:0> 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ? note 1: the t1ecs bits are valid only when tcs = 1 .
? 2011 microchip technology inc. ds31037b-page 117 pic24f16kl402 family 13.0 timer2 module the timer2 module incorporates the following features: ? 8-bit timer and period registers (tmr2 and pr2, respectively) ? readable and writable (both registers) ? software programmable prescaler (1:1, 1:4 and 1:16) ? software programmable postscaler (1:1 through 1:16) ? interrupt on tmr2 to pr2 match ? optional timer3 gate on tmr2 to pr2 match ? optional use as the shift clock for the mssp modules this module is controlled through the t2con register ( register 13-1 ), which enables or disables the timer and configures the prescaler and postscaler. timer2 can be shut off by clearing control bit, tmr2on (t2con<2>), to minimize power consumption. the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmr2 register ? a write to the t2con register ? any device reset (por, bor, mclr , or wdt reset) tmr2 is not cleared when t2con is written. a simplified block diagram of the module is shown in figure 13-1 . figure 13-1: timer2 block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on timers, refer to the ?pic24f family refer- ence manual? , section 14. ?timers? (ds39704). comparator tmr2 output tmr2 postscaler prescaler pr2 2 f osc /2 1:1 to 1:16 1:1, 1:4, 1:16 4 t2outps<3:0> t2ckps<1:0> set t2if internal data bus 8 reset tmr2/pr2 8 8 (to pwm or msspx) match
pic24f16kl402 family ds31037b-page 118 ? 2011 microchip technology inc. register 13-1: t2con: ti mer2 control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-3 t2outps<3:0>: timer2 output postscale select bits 1111 = 1:16 postscale 1110 = 1:15 postscale ? ? ? 0001 = 1:2 postscale 0000 = 1:1 postscale bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 10 = prescaler is 16 01 = prescaler is 4 00 = prescaler is 1
? 2011 microchip technology inc. ds31037b-page 119 pic24f16kl402 family 14.0 timer3 module the timer3 timer/counter modules incorporate these features: ? software-selectable operation as a 16-bit timer or counter ? one 16-bit readable and writable timer value register ? selectable clock source (internal or external) with device clock, sosc or lprc oscillator options ? interrupt-on-overflow ? multiple timer gating options, including: - user-selectable gate sources and polarity - gate/toggle operation - single-pulse (one-shot) mode ? module reset on eccp special event trigger the timer3 module is controlled through the t3con register ( register 14-1 ). a simplified block diagram of the timer3 module is shown in figure 14-1 . the f osc clock source should not be used with the eccp capture/compare features. if the timer will be used with the capture or compare features, always select one of the other timer clocking options. figure 14-1: timer3 block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on timers, refer to the ?pic24f family refer- ence manual? , section 14. ?timers? (ds39704). tmr3 t3sync t3ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit, t3if, on overflow t3g f osc sosco/t1ck sosci t3oscen 1 0 t3ck tmr3cs<1:0> gate sync tmr3ge 00 01 10 11 c1out t3gpol t3gtm t3gspm t3ggo t3gss<1:0> en 10 00 01 f osc /2 c2out/lprc tmr2 match set t3gif d q soscen sosc 16 to g g l e select one-shot select gate control sosc components 16 internal data bus 11 lprc
pic24f16kl402 family ds31037b-page 120 ? 2011 microchip technology inc. register 14-1: t3con: ti mer3 control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 t3oscen t3sync ? tmr3on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7-6 tmr3cs<1:0>: clock source select bits 11 = low-power rc oscillator (lprc) 10 = external clock source (selected by t3con<3>) 01 = instruction clock (f osc /2) 00 = system clock (f osc ) ( 1 ) bit 5-4 t3ckps<1:0> : timer3 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t3oscen : timer oscillator enable bit 1 = sosc (secondary oscillator) is used as a clock source 0 = t3ck digital input pin is used as a clock source bit 2 t3sync : external clock input synchronization control bit when tmr3cs<1:0> = 1 x : 1 = do not synchronize the external clock input 0 = synchronize the external clock input ( 2 ) when tmr3cs<1:0> = 0x : this bit is ignored; timer3 uses the internal clock. bit 1 unimplemented: read as ? 0 ? bit 0 tmr3on: timer on bit 1 = enables timer 0 = stops timer note 1: the f osc clock source should not be selected if the timer will be used with the eccp capture or compare features. 2: this option must be selected when the timer will be used with eccp/ccp.
? 2011 microchip technology inc. ds31037b-page 121 pic24f16kl402 family register 14-2: t3gcon: timer3 gate control register ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmr3ge t3gpol t3gtm t3gspm t3ggo/ t3done t3gval t3gss1 t3gss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 tmr3ge: timer gate enable bit if tmr3on = 0 : this bit is ignored. if tmr3on = 1 : 1 = timer counting is controlled by the timer3 gate function 0 = timer counts regardless of the timer3 gate function bit 6 t3gpol: gate polarity bit 1 = timer gate is active-high (timer3 counts when the gate is high) 0 = timer gate is active-low (timer3 counts when the gate is low) bit 5 t3gtm: gate toggle mode bit 1 = timer gate toggle mode is enabled. 0 = timer gate toggle mode is disabled and toggle flip-flop is cleared timer3 gate flip-flop toggles on every rising edge. bit 4 t3gspm: timer gate single pulse mode bit 1 = timer gate single pulse mode is enabled and is controlling timer3 gate 0 = timer gate single pulse mode is disabled bit 3 t3ggo/t3done : timer gate single pulse acquisition status bit 1 = timer gate single pulse acquisition is ready, waiting for an edge 0 = timer gate single pulse acquisition has completed or has not been started this bit is automatically cleared when txgspm is cleared. bit 2 t3gval: timer gate current state bit indicates the current state of the timer gate that could be provided to the tmr3 register; unaffected by the state of tmr3ge. bit 1-0 t3gss<1:0>: timer gate source select bits 11 = comparator 2 output 10 = comparator 1 output 01 = tmr2 to match pr2 output 00 = t3g input pin note 1: initializing t3gcon prior to t3con is recommended.
pic24f16kl402 family ds31037b-page 122 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 123 pic24f16kl402 family 15.0 timer4 module the timer4 module is implemented in pic24fxxkl30x/40x devices only. it has the following features: ? eight-bit timer register (tmr4) ? eight-bit period register (pr4) ? readable and writable (all registers) ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) ? interrupt on tmr4 match of pr4 the timer4 module has a control register shown in register 15-1 . timer4 can be shut off by clearing control bit, tmr4on (t4con<2>), to minimize power consumption. the prescaler and postscaler selection of timer4 is controlled by this register. the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmr4 register ? a write to the t4con register ? any device reset (por, bor, mclr or wdt reset) tmr4 is not cleared when t4con is written. figure 15-1 is a simplified block diagram of the timer4 module. figure 15-1: timer4 block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on timers, refer to the ?pic24f family refer- ence manual? , section 14. ?timers? (ds39704). comparator tmr4 output tmr4 postscaler prescaler pr4 2 f osc /2 1:1 to 1:16 1:1, 1:4, 1:16 4 t4outps<3:0> t4ckps<1:0> set t4if internal data bus 8 reset tmr4/pr4 8 8 (to pwm) match
pic24f16kl402 family ds31037b-page 124 ? 2011 microchip technology inc. register 15-1: t4con: ti mer4 control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-3 t4outps<3:0>: timer4 output postscale select bits 1111 = 1:16 postscale 1110 = 1:15 postscale ? ? ? 0001 = 1:2 postscale 0000 = 1:1 postscale bit 2 tmr4on: timer4 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t4ckps<1:0>: timer4 clock prescale select bits 10 = prescaler is 16 01 = prescaler is 4 00 = prescaler is 1
? 2011 microchip technology inc. ds31037b-page 125 pic24f16kl402 family 16.0 capture/compare/pwm (ccp) and enhanced ccp modules depending on the particular device, pic24f16kl402 family devices include up to three ccp and/or eccp modules. key features of all ccp modules include: ? 16-bit input capture for a range of edge events ? 16-bit output compare with multiple output options ? single-output pulse width modulation (pwm) with up to 10 bits of resolution ? user-selectable time base from any available timer ? special event trigger on capture and compare events to automatically trigger a range of peripherals eccp modules also include these features: ? operation in half-bridge and full-bridge (forward and reverse) modes ? pulse steering control across any or all enhanced pwm pins, with user-configurable steering synchronization ? user-configurable external fault detect with auto-shutdown and auto restart pic24fxxkl40x/30x devices instantiate three ccp modules, one enhanced (ccp1) and two standard (ccp2 and ccp). all other devices instantiate two standard ccp modules (ccp1 and ccp2). 16.1 timer selection on all pic24f16kl402 family devices, the ccp and eccp modules use timer3 as the time base for cap- ture and compare operations. pwm and enhanced pwm operations may use either timer2 or timer4. pwm time base selection is done through the ccptmrs0 register ( register 16-6 ). 16.2 ccp i/o pins to configure i/o pins with a ccp function, the proper mode must be selected by setting the ccpxm<3:0> bits. where the enhanced ccp module is available, it may have up to four pwm outputs, depending on the selected operating mode. these outputs are desig- nated, p1a through p1d. the outputs that are active depend on the eccp operating mode selected. to configure i/o pins for enhanced pwm operation, the proper pwm mode must be selected by setting the pm<1:0> and ccpm<3:0> bits. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the capture/compare/pwm module, refer to the ?pic24f family reference manual? .
pic24f16kl402 family ds31037b-page 126 ? 2011 microchip technology inc. figure 16-1: generic capt ure mode block diagram figure 16-2: generic comp are mode block diagram figure 16-3: simplified pwm block diagram ccprxh ccprxl set ccpxif q1:q4 ccpxcon<3:0> (e)ccpx pin prescaler ? 1, 4, 16 and edge detect tmr3h tmr3l 4 4 ccprxh ccprxl tmr3h tmr3l comparator q s r output logic special event trigger set ccpxif ccpx pin ccp ccpxcon<3:0> output enable compare 4 (timer3 reset) match ccprxl ccprxh (slave) comparator tmr2 (2) comparator pr2 (2) (1) r q s duty cycle registers ccpxcon<5:4> clear timer, ccp1 pin and latch d.c. ccp ccpx note 1: the 8-bit tmr2 value is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler, to create the 10-bit time bas e. 2: either timer2 or timer4 may be used as the pwm time base. output enable
? 2011 microchip technology inc. ds31037b-page 127 pic24f16kl402 family figure 16-4: simplified block diagram of enhanced pwm mode dc1b<1:0> eccp enable eccp1/p1a output eccp enable p1b output eccp enable p1c output eccp enable p1d output pm<1:0> 2 ccp1m<3:0> 4 eccp1del ccpr1l ccpr1h (slave) comparator tmr2 (2) comparator pr2 (2) (1) r q s duty cycle registers clear timer, ccp1 pin and latch d.c. note 1: the 8-bit tmr2 value is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler, to create the 10-bit time bas e. 2: either timer2 or timer4 may be used as the enhanced pwm time base. output controller eccp1/p1a p1b p1c p1d
pic24f16kl402 family ds31037b-page 128 ? 2011 microchip technology inc. register 16-1: ccpxcon: ccpx cont rol register (standard ccp modules) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dcxb1 dcxb0 ccpxm3 ( 1 ) ccpxm2 ( 1 ) ccpxm1 ( 1 ) ccpxm0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 unimplemented: read as ? 0 ? bit 5-4 dcxb<1:0> : pwm duty cycle bit 1 and bit 0 for ccpx module capture and compare modes : unused. pwm mode: these bits are the two least significant bits (bit 1 and bit 0) of the 10-bit pwm duty cycle. the eight most significant bits (dcxb<9:2>) of the duty cycle are found in ccprxl. bit 3-0 ccpxm<3:0> : ccpx module mode select bits ( 1 ) 1111 = reserved 1110 = reserved 1101 = reserved 1100 =pwm mode 1011 = compare mode: special event trigger; reset timer on ccpx match (ccpxif bit is set) 1010 = compare mode: generate software interrupt on compare match (ccpxif bit is set, ccpx pin reflects i/o state) 1001 = compare mode: initialize ccpx pin high; on compare match, force ccpx pin low (ccpxif bit is set) 1000 = compare mode: initialize ccpx pin low; on compare match, force ccpx pin high (ccpxif bit is set) 0111 = capture mode: every 16th rising edge 0110 = capture mode: every 4th rising edge 0101 = capture mode: every rising edge 0100 = capture mode: every falling edge 0011 = reserved 0010 = compare mode: toggle output on match (ccpxif bit is set) 0001 = reserved 0000 = capture/compare/pwm is disabled (resets ccpx module) note 1: ccpxm<3:0> = 1011 will only reset the timer and not start the a/d conversion on a ccpx match.
? 2011 microchip technology inc. ds31037b-page 129 pic24f16kl402 family register 16-2: ccp1con: eccp1 cont rol register (eccp modules only) ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pm1 pm0 dc1b1 dc1b0 ccp1m3 ( 2 ) ccp1m2 ( 2 ) ccp1m1 ( 2 ) ccp1m0 ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7-6 pm<1:0>: enhanced pwm output configuration bits if ccp 1m <3:2> = 00 , 01 , 10 : xx = p1a is assigned as capture input or compare output; p1b, p1c and p1d are assigned as port pins if ccp 1m <3:2> = 11 : 11 = full-bridge output reverse: p1b is modulated; p1c is active; p1a and p1d are inactive 10 = half-bridge output: p1a, p1b are modulated with dead-band control; p1c and p1d are assigned as port pins 01 = full-bridge output forward: p1d is modulated; p1a is active; p1b, p1c are inactive 00 = single output: p1a, p1b, p1c and p1d are controlled by steering bit 5-4 dc1b<1:0> : pwm duty cycle bit 1 and bit 0 for ccp1 module capture and compare modes : unused. pwm mode: these bits are the two least significant bits (bit 1 and bit 0) of the 10-bit pwm duty cycle. the eight most significant bits (dc1b<9:2>) of the duty cycle are found in ccpr1l. bit 3-0 ccp1m<3:0> : ccp1 module mode select bits ( 2 ) 1111 = pwm mode: pa and pc are active-low; pb and pd are active-low 1110 = pwm mode: pa and pc are active-low; pb and pd are active-high 1101 = pwm mode: pa and pc are active-high; pb and pd are active-low 1100 = pwm mode: pa and pc are active-high; pb and pd are active-high 1011 = compare mode: special event trigger; reset timer on ccp1 match (ccpxif bit is set) 1010 = compare mode: generate software interrupt on compare match (ccp1if bit is set, ccp1 pin reflects i/o state) 1001 = compare mode: initialize ccp1 pin high; on compare match, force ccp1 pin low (ccp1if bit is set) 1000 = compare mode: initialize ccp1 pin low; on compare match, force ccp1 pin high (ccp1if bit is set) 0111 = capture mode: every 16th rising edge 0110 = capture mode: every 4th rising edge 0101 = capture mode: every rising edge 0100 = capture mode: every falling edge 0011 = reserved 0010 = compare mode: toggle output on match (ccp1if bit is set) 0001 = reserved 0000 = capture/compare/pwm is disabled (resets ccp1 module) note 1: this register is implemented only on pic24fxxkl40x/30x devices. for all other devices, ccp1con is configured as register 16-1 . 2: ccp1m<3:0> = 1011 will only reset timer and not start a/d conversion on ccp1 match.
pic24f16kl402 family ds31037b-page 130 ? 2011 microchip technology inc. register 16-3: eccp1as: eccp1 auto-shutdown control register ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 eccpase: eccp auto-shutdown event status bit 1 = a shutdown event has occurred; eccp outputs are in a shutdown state 0 = eccp outputs are operating bit 6-4 eccpas<2:0>: eccp auto-shutdown source select bits 111 =v il on flt0 pin, or either c1out or c2out is high 110 =v il on flt0 pin, or c2out comparator output is high 101 =v il on flt0 pin, or c1out comparator output is high 100 =v il on flt0 pin 011 = either c1out or c2out is high 010 = c2out comparator output is high 001 = c1out comparator output is high 000 = auto-shutdown is disabled bit 3-2 pssac<1:0>: pxa and pxc pins shutdown state control bits 1x = p1a and p1c pins tri-state 01 = drive pins p1a and p1c to ? 1 ? 00 = drive pins p1a and p1c to ? 0 ? bit 1-0 pssbd<1:0>: pxb and pxd pins shutdown state control bits 1x = p1b and p1d pins tri-state 01 = drive pins, p1b and p1d, to ? 1 ? 00 = drive pins, p1b and p1d, to ? 0 ? note 1: this register is implemented only on pic24fxxkl40x/30x devices. note 1: the auto-shutdown condition is a level-based signal, not an edge-based signal. as long as the level is present, the auto-shutdown will persist. 2: writing to the eccpase bit is disabled while an auto-shutdown condition persists. 3: once the auto-shutdown condition has been removed and the pwm restarted (either through firmware or auto-restart), the pwm signal will always restart at the beginning of the next pwm period.
? 2011 microchip technology inc. ds31037b-page 131 pic24f16kl402 family register 16-4: eccp1del: eccp 1 enhanced pwm control register ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 prsen: pwm restart enable bit 1 = upon auto-shutdown, the eccpase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccpase must be cleared by software to restart the pwm bit 6-0 pdc<6:0>: pwm delay count bits pdcn = number of f cy (f osc /2) cycles between the scheduled time when a pwm signal should transition active and the actual time it transitions active. note 1: this register is implemented only on pic24fxxkl40x/30x devices.
pic24f16kl402 family ds31037b-page 132 ? 2011 microchip technology inc. register 16-5: pstr1con: pulse steering control register for eccp1 ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 cmpl1 cmpl0 ? strsync strd strc strb stra bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7-6 cmpl<1:0>: complementary mode output assignment steering bits 00 = complementary output assignment is disabled; the str bits are used to determine steering mode 01 = pxa and pxb are selected as the complementary output pair 10 = pxa and pxc are selected as the complementary output pair 11 = pxa and pxd are selected as the complementary output pair bit 5 unimplemented: read as ? 0 ? bit 4 strsync: steering sync bit 1 = output steering update occurs on the next pwm period 0 = output steering update occurs at the beginning of the instruction cycle boundary bit 3 strd: steering enable d bit 1 = p1d pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1d pin is assigned to port pin bit 2 strc: steering enable c bit 1 = p1c pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1c pin is assigned to port pin bit 1 strb: steering enable b bit 1 = p1b pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1b pin is assigned to port pin bit 0 stra: steering enable a bit 1 = p1a pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1a pin is assigned to port pin note 1: this register is only implemented on pic24fxxkl40x/30x devices. in addition, pwm steering mode is available only when ccp1m<3:2> = 11 and pm<1:0> = 00 .
? 2011 microchip technology inc. ds31037b-page 133 pic24f16kl402 family register 16-6: ccptmrs0: ccp time r select control register 0 ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 u-0 u-0 r/w-0 u-0 u-0 r/w-0 ? c3tsel0 ? ? c2tsel0 ? ? c1tsel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6 c3tsel0: ccp3 timer selection bit 1 = ccp3 uses tmr3/tmr4 0 = ccp3 uses tmr3/tmr2 bit 5-4 unimplemented: read as ? 0 ? bit 3 c2tsel0: ccp2 timer selection bit 1 = ccp2 uses tmr3/tmr4 0 = ccp2 uses tmr3/tmr2 bit 2-1 unimplemented: read as ? 0 ? bit 0 c1tsel0: ccp1/eccp1 timer selection bit 1 = ccp1/eccp1 uses tmr3/tmr4 0 = ccp1/eccp1 uses tmr3/tmr2 note 1: this register is unimplemented on pic24fxxkl20x/10x devices; maintain as ? 0 ?.
pic24f16kl402 family ds31037b-page 134 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 135 pic24f16kl402 family 17.0 master synchronous serial port (mssp) the master synchronous serial port (mssp) module is an 8-bit serial interface, useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift reg- isters, display drivers, a/d converters, etc. the mssp module can operate in one of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit (i 2 c?) - full master mode - slave mode (with general address call) the spi interface supports these modes in hardware: ?master mode ? slave mode ? daisy-chaining operation in slave mode ? synchronized slave operation the i 2 c interface supports the following modes in hardware: ?master mode ? multi-master mode ? slave mode with 10-bit and 7-bit addressing and address masking ?byte nacking ? selectable address and data hold and interrupt masking 17.1 i/o pin configuration for spi in spi master mode, the mssp module will assert con- trol over any pins associated with the sdox and sckx outputs. this does not automatically disable other digi- tal functions associated with the pin, and may result in the module driving the digital i/o port inputs. to prevent this, the mssp module outputs must be disconnected from their output pins while the module is in spi master mode. while disabling the module temporarily may be an option, it may not be a practical solution in all applications. the sdox and sckx outputs for the module can be selectively disabled by using the sdoxdis and sckxdis bits in the padcfg1 register ( register 17-10 ). setting the bit disconnects the corresponding output for a particular module from its assigned pin. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on mssp, refer to the ?pic24f family reference manual? .
pic24f16kl402 family ds31037b-page 136 ? 2011 microchip technology inc. figure 17-1: mssp block diagram (spi mode) figure 17-2: spi mast er/slave connection ( ) read write internal data bus sspxsr sspm<3:0> bit 0 shift clock ssx control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to txx/rxx in sspxsr tris bit 2 smp:cke sdox sspxbuf sdix ssx sckx note: refer to the device data sheet for pin multiplexing. baud rate generator sspxadd<7:0> 7 serial input buffer (sspxbuf) shift register (sspxsr) msb lsb sdox sdix processor 1 sckx spi master sspm<3:0> = 00xx serial input buffer (sspxbuf) shift register (sspxsr) lsb msb sdix sdox processor 2 sckx spi slave sspm<3:0> = 010x serial clock
? 2011 microchip technology inc. ds31037b-page 137 pic24f16kl402 family figure 17-3: mssp block diagram (i 2 c? mode) figure 17-4: mssp block diagram (i 2 c? master mode) sspxsr match detect sspxadd sspxbuf internal data bus address match set/reset s, p bits shift clock msb lsb note: only port i/o names are shown in this diagram. refer to the text for a full list of multiplexed functions. sclx sdax start and stop bit detect address mask read write start bit, stop bit, internal data bus set/reset s, p (sspxstat), wcol shift clock msb lsb sdax acknowledge generate stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv sclx sclx in bus collision sdax in rcv enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspxadd<6:0> baud set sspxif, bclxif reset ackstat, pen rate generator sspm<3:0> start bit detect sspxsr sspxbuf read write
pic24f16kl402 family ds31037b-page 138 ? 2011 microchip technology inc. register 17-1: sspxstat: msspx status register (spi mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke ( 1 ) d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 smp: sample bit spi master mode: 1 = input data is sampled at the end of data output time 0 = input data is sampled at the middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode. bit 6 cke: spi clock select bit ( 1 ) 1 = transmit occurs on transition from active to idle clock state 0 = transmit occurs on transition from idle to active clock state bit 5 d/a : data/address bit used in i 2 c? mode only. bit 4 p: stop bit used in i 2 c mode only. this bit is cleared when the msspx module is disabled; sspen is cleared. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write information bit used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf: buffer full status bit 1 = receive is complete, sspxbuf is full 0 = receive is not complete, sspxbuf is empty note 1: polarity of clock state is set by the ckp bit (sspxcon1<4>).
? 2011 microchip technology inc. ds31037b-page 139 pic24f16kl402 family register 17-2: sspxstat: msspx status register (i 2 c? mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a p ( 1 ) s ( 1 ) r/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 smp: slew rate control bit in master or slave mode: 1 = slew rate control is disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control is enabled for high-speed mode (400 khz) bit 6 cke: smbus select bit in master or slave mode: 1 = enable smbus specific inputs 0 = disable smbus specific inputs bit 5 d/a : data/address bit in master mode: reserved. in slave mode: 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit ( 1 ) 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last bit 3 s: start bit ( 1 ) 1 = indicates that a start bit has been detected last 0 = start bit was not detected last bit 2 r/w : read/write information bit in slave mode: ( 2 ) 1 = read 0 = write in master mode: ( 3 ) 1 = transmit is in progress 0 = transmit is not in progress bit 1 ua: update address bit (10-bit slave mode only) 1 = indicates that the user needs to update the address in the sspxadd register 0 = address does not need to be updated note 1: this bit is cleared on reset and when sspen is cleared. 2: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. 3: oring this bit with sen, rsen, pen, rcen or acken w ill indicate if the msspx is in active mode.
pic24f16kl402 family ds31037b-page 140 ? 2011 microchip technology inc. bit 0 bf: buffer full status bit in transmit mode: 1 = transmit is in progress, sspxbuf is full 0 = transmit is complete, sspxbuf is empty in receive mode: 1 = sspxbuf is full (does not include the ack and stop bits) 0 = sspxbuf is empty (does not include the ack and stop bits) register 17-2: sspxstat: msspx status register (i 2 c? mode) (continued) note 1: this bit is cleared on reset and when sspen is cleared. 2: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. 3: oring this bit with sen, rsen, pen, rcen or acken w ill indicate if the msspx is in active mode.
? 2011 microchip technology inc. ds31037b-page 141 pic24f16kl402 family register 17-3: sspxcon1: msspx co ntrol register 1 (spi mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov ( 1 ) sspen ( 2 ) ckp sspm3 ( 3 ) sspm2 ( 3 ) sspm1 ( 3 ) sspm0 ( 3 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 wcol: write collision detect bit 1 = the sspxbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit ( 1 ) spi slave mode: 1 = a new byte is received while the sspxbuf register is still holding the previous data. in case of over- flow, the data in sspxsr is lost. overflow can only occur in slave mode. the user must read the sspxbuf, even if only transmitting data, to avoid setting overflow (must be cleared in software). 0 = no overflow bit 5 sspen: master synchronous serial port enable bit ( 2 ) 1 = enables serial port and configures sckx, sdox, sdix and ssx as serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: clock polarity select bit 1 = idle state for clock is a high level 0 = idle state for clock is a low level bit 3-0 sspm<3:0>: master synchronous serial port mode select bits ( 3 ) 1010 = spi master mode, clock = f osc /(2 * ([sspxadd] + 1)) 0101 = spi slave mode, clock = sckx pin; ssx pin control is disabled, ssx can be used as an i/o pin 0100 = spi slave mode, clock = sckx pin; ssx pin control is enabled 0011 = spi master mode, clock = tmr2 output/2 0010 = spi master mode, clock = f osc /32 0001 = spi master mode, clock = f osc /8 0000 = spi master mode, clock = f osc /2 note 1: in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspxbuf register. 2: when enabled, these pins must be properly configured as input or output. 3: bit combinations not specifically listed here are either reserved or implemented in i 2 c mode only.
pic24f16kl402 family ds31037b-page 142 ? 2011 microchip technology inc. register 17-4: sspxcon1: msspx control register 1 (i 2 c? mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ( 1 ) ckp sspm3 ( 2 ) sspm2 ( 2 ) sspm1 ( 2 ) sspm0 ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 wcol: write collision detect bit in master transmit mode: 1 = a write to the sspxbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started (must be cleared in software) 0 = no collision in slave transmit mode: 1 = the sspxbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision in receive mode (master or slave modes): this is a ?don?t care? bit. bit 6 sspov: receive overflow indicator bit in receive mode: 1 = a byte is received while the sspxbuf register is still holding the previous byte (must be cleared in software) 0 = no overflow in transmit mode: this is a ?don?t care? bit in transmit mode. bit 5 sspen: master synchronous serial port enable bit ( 1 ) 1 = enables the serial port and configures the sdax and sclx pins as the serial port pins 0 = disables the serial port and configures these pins as i/o port pins bit 4 ckp: sclx release control bit in slave mode: 1 = releases clock 0 = holds clock low (clock stretch), used to ensure data setup time in master mode: unused in this mode. bit 3-0 sspm<3:0>: master synchronous serial port mode select bits ( 2 ) 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts is enabled 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts is enabled 1011 = i 2 c firmware controlled master mode (slave idle) 1000 = i 2 c master mode, clock = f osc /(2 * ([sspxadd] + 1)) ( 3 ) 0111 = i 2 c slave mode, 10-bit address 0110 = i 2 c slave mode, 7-bit address note 1: when enabled, the sdax and sclx pins must be configured as inputs. 2: bit combinations not specifically listed here are either reserved or implemented in spi mode only. 3: sspxadd values of 0, 1 or 2 are not supported when the baud rate generator is used with i 2 c mode.
? 2011 microchip technology inc. ds31037b-page 143 pic24f16kl402 family register 17-5: sspxcon2: m sspx control register 2 (i 2 c? mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt ( 1 ) acken ( 2 ) rcen ( 2 ) pen ( 2 ) rsen ( 2 ) sen ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 gcen: general call enable bit (slave mode only) 1 = enables interrupt when a general call address (0000h) is received in the sspxsr 0 = general call address is disabled bit 6 ackstat: acknowledge status bit (master transmit mode only) 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (master receive mode only) ( 1 ) 1 = no acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit (master mode only) ( 2 ) 1 = initiates acknowledge sequence on sdax and sclx pins and transmits ackdt data bit; automatically cleared by hardware 0 = acknowledge sequence is idle bit 3 rcen: receive enable bit (master receive mode only) ( 2 ) 1 = enables receive mode for i 2 c 0 = receive is idle bit 2 pen: stop condition enable bit (master mode only) ( 2 ) 1 = initiates stop condition on sdax and sclx pins; automatically cleared by hardware 0 = stop condition is idle bit 1 rsen: repeated start condition enable bit (master mode only) ( 2 ) 1 = initiates repeated start condition on sdax and sclx pins; automatically cleared by hardware 0 = repeated start condition is idle bit 0 sen: start condition enable bit ( 2 ) master mode: 1 = initiates start condition on sdax and sclx pins; automatically cleared by hardware 0 = start condition is idle slave mode: 1 = clock stretching is enabled for both slave transmit and slave receive (stretch is enabled) 0 = clock stretching is disabled note 1: the value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. 2: if the i 2 c module is active, these bits may not be set (no spooling) and the sspxbuf may not be written (or writes to the sspxbuf are disabled).
pic24f16kl402 family ds31037b-page 144 ? 2011 microchip technology inc. register 17-6: sspxcon3: msspx co ntrol register 3 (spi mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 acktim pcie scie boen ( 1 ) sdaht sbcde ahen dhen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 acktim: acknowledge time status bit (i 2 c? mode only) unused in spi mode. bit 6 pcie : stop condition interrupt enable bit (i 2 c mode only) unused in spi mode. bit 5 scie : start condition interrupt enable bit (i 2 c mode only) unused in spi mode. bit 4 boen: buffer overwrite enable bit ( 1 ) in spi slave mode: 1 = sspxbuf updates every time that a new data byte is shifted in, ignoring the bf bit 0 = if a new byte is received with the bf bit of the sspxstat register already set, the sspxov bit of the sspxcon1 register is set and the buffer is not updated bit 3 sdaht: sdax hold time selection bit (i 2 c mode only) unused in spi mode. bit 2 sbcde: slave mode bus collision detect enable bit (i 2 c slave mode only) unused in spi mode. bit 1 ahen: address hold enable bit (i 2 c slave mode only) unused in spi mode. bit 0 dhen: data hold enable bit (slave mode only) unused in spi mode. note 1: for daisy-chained spi operation: allows the user to ignore all but the last received byte. sspxov is still set when a new byte is received and bf = 1 , but hardware continues to write the most recent byte to sspxbuf.
? 2011 microchip technology inc. ds31037b-page 145 pic24f16kl402 family register 17-7: sspxcon3: m sspx control register 3 (i 2 c? mode) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 acktim ( 1 ) pcie scie boen sdaht sbcde ahen dhen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 acktim: acknowledge time status bit ( 1 ) 1 = indicates the i 2 c bus is in an acknowledge sequence, set on the 8 th falling edge of the sclx clock 0 = not an acknowledge sequence, cleared on 9 th rising edge of sclx clock bit 6 pcie : stop condition interrupt enable bit 1 = enable interrupt on detection of stop condition 0 = stop detection interrupts are disabled ( 2 ) bit 5 scie : start condition interrupt enable bit 1 = enable interrupt on detection of start or restart conditions 0 = start detection interrupts are disabled ( 2 ) bit 4 boen: buffer overwrite enable bit i . 2 c master mode: this bit is ignored. i 2 c slave mode: 1 = sspxbuf is updated and an ack is generated for a received address/data byte, ignoring the state of the sspxov bit only if the bf bit = 0 0 = sspxbuf is only updated when sspxov is clear bit 3 sdaht: sdax hold time selection bit 1 = minimum of 300 ns hold time on sdax after the falling edge of sclx 0 = minimum of 100 ns hold time on sdax after the falling edge of sclx bit 2 sbcde: slave mode bus collision detect enable bit (slave mode only) 1 = enables slave bus collision interrupts 0 = slave bus collision interrupts are disabled bit 1 ahen: address hold enable bit (slave mode only) 1 = following the 8th falling edge of sclx for a matching received address byte; ckp bit of the sspxcon1 register will be cleared and the sclx will be held low. 0 = address holding is disabled bit 0 dhen: data hold enable bit (slave mode only) 1 = following the 8th falling edge of sclx for a received data byte; slave hardware clears the ckp bit of the sspxcon1 register and sclx is held low. 0 = data holding is disabled note 1: this bit has no effect in slave modes for which start and stop condition detection is explicitly listed as enabled. 2: the acktim status bit is active only when the ahen bit or dhen bit is set.
pic24f16kl402 family ds31037b-page 146 ? 2011 microchip technology inc. register 17-8: sspxadd: msspx slave address/baud rate generator register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 add7 add6 add5 add4 add3 add2 add1 add0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7-0 add<7:0>: slave address/baud rate generator value bits spi master and i 2 c master modes: reload value for baud rate generator. clock period is (([spxadd] + 1) *2)/f osc . i 2 c? slave modes: represents 7 or 8 bits of the slave address, depending on the addressing mode used: 7-bit mode : address is add<7:1>; add<0> is ignored. 10-bit lsb mode : add<7:0> are the least significant bits of the address. 10-bit msb mode : add<2:1> are the two most significant bits of the address; add<7:3> are always ? 11110 ? as a specification requirement; add<0> is ignored. register 17-9: sspxmsk: i 2 c slave address mask register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7-0 msk<7:0>: slave address mask select bit ( 1 ) 1 = masking of corresponding bit of sspxadd enabled 0 = masking of corresponding bit of sspxadd disabled note 1: msk0 is not used as a mask bit in 7-bit addressing.
? 2011 microchip technology inc. ds31037b-page 147 pic24f16kl402 family register 17-10: padcfg1: pad co nfiguration control register u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ?sdo2dis ( 1 ) sck2dis ( 1 ) sdo1dis sck1dis bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 11 sdo2dis: mssp2 sdo pin disable bit ( 1 ) 1 = the spi output data (sdo2) of mssp2 to the pin is disabled 0 = the spi output data (sdo2) of mssp2 is output to the pin bit 10 sck2dis: mssp2 sck pin disable bit ( 1 ) 1 = the spi clock (sck2) of mssp2 to the pin is disabled 0 = the spi clock (sck2) of mssp2 is output to the pin bit 9 sdo1dis: mssp1 sdo pin disable bit 1 = the spi output data (sdo1) of mssp1 to the pin is disabled 0 = the spi output data (sdo1) of mssp1 is output to the pin bit 8 sck1dis: mssp1 sck pin disable bit 1 = the spi clock (sck1) of mssp1 to the pin is disabled 0 = the spi clock (sck1) of mssp1 is output to the pin bit 7-0 unimplemented: read as ? 0 ? note 1: these bits are implemented only on pic24fxxkl40x/30x devices.
pic24f16kl402 family ds31037b-page 148 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 149 pic24f16kl402 family 18.0 universal asynchronous receiver transmitter (uart) the universal asynchronous receiver transmitter (uart) module is one of the serial i/o modules available in this pic24f device family. the uart is a full-duplex, asynchronous system that can communicate with peripheral devices, such as personal computers, lin/j2602, rs-232 and rs-485 interfaces. this module also supports a hardware flow control option with the uxcts and uxrts pins, and also includes an irda ? encoder and decoder. the primary features of the uart module are: ? full-duplex, 8-bit or 9-bit data transmission through the uxtx and uxrx pins ? even, odd or no parity options (for 8-bit data) ? one or two stop bits ? hardware flow control option with uxcts and uxrts pins ? fully integrated baud rate generator (ibrg) with 16-bit prescaler ? baud rates ranging from 1 mbps to 15 bps at 16 mips ? two-level deep, first-in-first-out (fifo) transmit data buffer ? two-level deep, fifo receive data buffer ? parity, framing and buffer overrun error detection ? support for 9-bit mode with address detect (9 th bit = 1 ) ? transmit and receive interrupts ? loopback mode for diagnostic support ? support for sync and break characters ? supports automatic baud rate detection ? irda encoder and decoder logic ? 16x baud clock output for irda support a simplified block diagram of the uart is shown in figure 18-1 . the uart module consists of these important hardware elements: ? baud rate generator ? asynchronous transmitter ? asynchronous receiver figure 18-1: uart simplified block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the universal asynchronous receiver transmitter, refer to the ?pic24f family reference manual? , section 21. ?uart? (ds39708). uxrx irda ? hardware flow control uartx receiver uartx transmitter uxtx uxcts uxrts uxbclk baud rate generator
pic24f16kl402 family ds31037b-page 150 ? 2011 microchip technology inc. 18.1 uart baud rate generator (brg) the uart module includes a dedicated 16-bit baud rate generator (brg). the uxbrg register controls the period of a free-running, 16-bit timer. equation 18-1 provides the formula for computation of the baud rate with brgh = 0 . equation 18-1: uart baud rate with brgh = 0 ( 1 ) example 18-1 provides the calculation of the baud rate error for the following conditions: ?f cy = 4 mhz ? desired baud rate = 9600 the maximum baud rate (brgh = 0 ) possible is f cy /16 (for uxbrg = 0 ) and the minimum baud rate possible is f cy /(16 * 65536). equation 18-2 shows the formula for computation of the baud rate with brgh = 1 . equation 18-2: uart baud rate with brgh = 1 ( 1 ) the maximum baud rate (brgh = 1 ) possible is f cy /4 (for uxbrg = 0 ) and the minimum baud rate possible is f cy /(4 * 65536). writing a new value to the uxbrg register causes the brg timer to be reset (cleared). this ensures the brg does not wait for a timer overflow before generating the new baud rate. example 18-1: baud rate erro r calculation (brgh = 0 ) ( 1 ) note 1: based on f cy = f osc /2; doze mode and pll are disabled. baud rate = f cy 16 ? (uxbrg + 1) f cy 16 ? baud rate uxbrg = ? 1 baud rate = f cy 4 ? (uxbrg + 1) f cy 4 ? baud rate uxbrg = ? 1 note 1: based on f cy = f osc /2; doze mode and pll are disabled. desired baud rate = f cy /(16 (uxbrg + 1)) solving for uxbrg value: uxbrg = ((f cy /desired baud rate)/16) ? 1 uxbrg = ((4000000/9600)/16) ? 1 uxbrg = 25 calculated baud rate = 4000000/(16 (25 + 1)) = 9615 error = (calculated baud rate ? desired baud rate) desired baud rate = (9615 ? 9600)/9600 =0.16% note 1: based on f cy = f osc /2; doze mode and pll are disabled.
? 2011 microchip technology inc. ds31037b-page 151 pic24f16kl402 family 18.2 transmitting in 8-bit data mode 1. set up the uart: a) write appropriate values for data, parity and stop bits. b) write appropriate baud rate value to the uxbrg register. c) set up transmit and receive interrupt enable and priority bits. 2. enable the uart. 3. set the utxen bit (causes a transmit interrupt, two cycles after being set). 4. write data byte to lower byte of uxtxreg word. the value will be immediately transferred to the transmit shift register (tsr) and the serial bit stream will start shifting out with the next rising edge of the baud clock. 5. alternately, the data byte may be transferred while utxen = 0 and then, the user may set utxen. this will cause the serial bit stream to begin immediately, because the baud clock will start from a cleared state. 6. a transmit interrupt will be generated as per interrupt control bit, utxiselx. 18.3 transmitting in 9-bit data mode 1. set up the uart (as described in section 18.2 ?transmitting in 8-bit data mode? ). 2. enable the uart. 3. set the utxen bit (causes a transmit interrupt, two cycles after being set). 4. write uxtxreg as a 16-bit value only. 5. a word write to uxtxreg triggers the transfer of the 9-bit data to the tsr. the serial bit stream will start shifting out with the first rising edge of the baud clock. 6. a transmit interrupt will be generated as per the setting of control bit, utxiselx. 18.4 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. 1. configure the uart for the desired mode. 2. set utxen and utxbrk ? sets up the break character. 3. load the uxtxreg with a dummy character to initiate transmission (value is ignored). 4. write ?55h? to uxtxreg ? loads the sync character into the transmit fifo. 5. after the break has been sent, the utxbrk bit is reset by hardware. the sync character now transmits. 18.5 receiving in 8-bit or 9-bit data mode 1. set up the uart (as described in section 18.2 ?transmitting in 8-bit data mode? ). 2. enable the uart. 3. a receive interrupt will be generated when one or more data characters have been received as per interrupt control bit, urxiselx. 4. read the oerr bit to determine if an overrun error has occurred. the oerr bit must be reset in software. 5. read uxrxreg. the act of reading the uxrxreg character will move the next character to the top of the receive fifo, including a new set of perr and ferr values. 18.6 operation of uxcts and uxrts control pins uartx clear-to-send (uxcts ) and request-to-send (uxrts ) are the two hardware-controlled pins that are associated with the uart module. these two pins allow the uart to operate in simplex and flow control modes. they are implemented to control the transmission and reception between the data terminal equipment (dte). the uen<1:0> bits in the uxmode register configure these pins. 18.7 infrared support the uart module provides two types of infrared uart support: one is the irda clock output to support an external irda encoder and decoder device (legacy module support), and the other is the full implementation of the irda encoder and decoder. as the irda modes require a 16x baud clock, they will only work when the brgh bit (uxmode<3>) is ? 0 ?. 18.7.1 external irda support ? irda clock output to support external irda encoder and decoder devices, the uxbclk pin (same as the uxrts pin) can be configured to generate the 16x baud clock. when uen<1:0> = 11 , the uxbclk pin will output the 16x baud clock if the uart module is enabled; it can be used to support the irda codec chip. 18.7.2 built-in irda encoder and decoder the uart has full implementation of the irda encoder and decoder as part of the uart module. the built-in irda encoder and decoder functionality is enabled using the iren bit (uxmode<12>). when enabled (iren = 1 ), the receive pin (uxrx) acts as the input from the infrared receiver. the transmit pin (uxtx) acts as the output to the infrared transmitter.
pic24f16kl402 family ds31037b-page 152 ? 2011 microchip technology inc. register 18-1: uxmode: uartx mode register r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 ( 2 ) r/w-0 ( 2 ) uarten ? usidl iren ( 1 ) rtsmd ? uen1 uen0 bit 15 bit 8 r/c-0, hc r/w-0 r/w-0, hc r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel bit 7 bit 0 legend: c = clearable bit hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 uarten: uartx enable bit 1 = uartx is enabled; all uartx pins are controlled by uartx as defined by uen<1:0> 0 = uartx is disabled; all uartx pins are controlled by port latches, uartx power consumption is minimal bit 14 unimplemented: read as ? 0 ? bit 13 usidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12 iren: irda ? encoder and decoder enable bit ( 1 ) 1 = irda encoder and decoder are enabled 0 = irda encoder and decoder are disabled bit 11 rtsmd: mode selection for uxrts pin bit 1 =uxrts pin is in simplex mode 0 =uxrts pin is in flow control mode bit 10 unimplemented: read as ? 0 ? bit 9-8 uen<1:0>: uartx enable bits ( 2 ) 11 = uxtx, uxrx and uxbclk pins are enabled and used; uxcts pin is controlled by port latches 10 = uxtx, uxrx, uxcts and uxrts pins are enabled and used 01 = uxtx, uxrx and uxrts pins are enabled and used; uxcts pin is controlled by port latches 00 = uxtx and uxrx pins are enabled and used; uxcts and uxrts /uxbclk pins are controlled by port latches bit 7 wake: wake-up on start bit detect during sleep mode enable bit 1 = uartx will continue to sample the uxrx pin; interrupt is generated on the falling edge, bit is cleared in hardware on the following rising edge 0 = no wake-up is enabled bit 6 lpback: uartx loopback mode select bit 1 = enable loopback mode 0 = loopback mode is disabled bit 5 abaud: auto-baud enable bit 1 = enable baud rate measurement on the next character ? requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement is disabled or completed bit 4 rxinv: receive polarity inversion bit 1 = uxrx idle state is ? 0 ? 0 = uxrx idle state is ? 1 ? note 1: this feature is is only available for the 16x brg mode (brgh = 0 ). 2: bit availability depends on pin availability.
? 2011 microchip technology inc. ds31037b-page 153 pic24f16kl402 family bit 3 brgh: high baud rate enable bit 1 = brg generates 4 clocks per bit period (4x baud clock, high-speed mode) 0 = brg generates 16 clocks per bit period (16x baud clock, standard mode) bit 2-1 pdsel<1:0>: parity and data selection bits 11 = 9-bit data, no parity 10 = 8-bit data, odd parity 01 = 8-bit data, even parity 00 = 8-bit data, no parity bit 0 stsel: stop bit selection bit 1 = two stop bits 0 = one stop bit register 18-1: uxmode: uartx mode register (continued) note 1: this feature is is only available for the 16x brg mode (brgh = 0 ). 2: bit availability depends on pin availability.
pic24f16kl402 family ds31037b-page 154 ? 2011 microchip technology inc. register 18-2: uxsta: uartx status and control register r/w-0 r/w-0 r/w-0 u-0 r/w-0, hc r/w-0 r-0, hsc r-1, hsc utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt bit 15 bit 8 r/w-0 r/w-0 r/w-0 r-1, hsc r-0, hsc r-0, hsc r/c-0, hs r-0, hsc urxisel1 urxisel0 adden ridle perr ferr oerr urxda bit 7 bit 0 legend: hc = hardware clearable bit hs = hardware settable bit c = clearable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15,13 utxisel<1:0>: transmission interrupt mode selection bits 11 = reserved; do not use 10 = interrupt when a character is transferred to the transmit shift register (tsr) and as a result, the transmit buffer becomes empty 01 = interrupt when the last character is shifted out of the transmit shift register; all transmit operations are completed 00 = interrupt when a character is transferred to the transmit shift register (this implies there is at least one character open in the transmit buffer) bit 14 utxinv: irda ? encoder transmit polarity inversion bit if iren = 0 : 1 = uxtx idle ? 0 ? 0 = uxtx idle ? 1 ? if iren = 1 : 1 = uxtx idle ? 1 ? 0 = uxtx idle ? 0 ? bit 12 unimplemented: read as ? 0 ? bit 11 utxbrk: transmit break bit 1 = send sync break on next transmission ? start bit, followed by twelve ? 0 ? bits; followed by stop bit; cleared by hardware upon completion 0 = sync break transmission is disabled or completed bit 10 utxen: transmit enable bit 1 = transmit is enabled; uxtx pin is controlled by uartx 0 = transmit is disabled; any pending transmission is aborted and the buffer is reset. uxtx pin is controlled by the port register. bit 9 utxbf: transmit buffer full status bit (read-only) 1 = transmit buffer is full 0 = transmit buffer is not full, at least one more character can be written bit 8 trmt: transmit shift register empty bit (read-only) 1 = transmit shift register is empty and the transmit buffer is empty (the last transmission has completed) 0 = transmit shift register is not empty; a transmission is in progress or queued bit 7-6 urxisel<1:0>: receive interrupt mode selection bits 11 = interrupt is set on the rsr transfer, making the receive buffer full (i.e., has 2 data characters) 10 = reserved 01 = reserved 00 = interrupt is set when any character is received and transferred from the rsr to the receive buffer; receive buffer has one or more characters
? 2011 microchip technology inc. ds31037b-page 155 pic24f16kl402 family bit 5 adden: address character detect bit (bit 8 of the received data = 1 ) 1 = address detect mode is enabled; if 9-bit mode is not selected, this does not take effect 0 = address detect mode is disabled bit 4 ridle: receiver idle bit (read-only) 1 = receiver is idle 0 = receiver is active bit 3 perr: parity error status bit (read-only) 1 = parity error has been detected for the current character (character at the top of the receive fifo) 0 = parity error has not been detected bit 2 ferr: framing error status bit (read-only) 1 = framing error has been detected for the current character (character at the top of the receive fifo) 0 = framing error has not been detected bit 1 oerr: receive buffer overrun error status bit (clear/read-only) 1 = receive buffer has overflowed 0 = receive buffer has not overflowed (clearing a previously set oerr bit ( 1 ? 0 transition) will reset the receiver buffer and the rsr to the empty state) bit 0 urxda: receive buffer data available bit (read-only) 1 = receive buffer has data; at least one more character can be read 0 = receive buffer is empty register 18-2: uxsta: uartx status and control register (continued)
pic24f16kl402 family ds31037b-page 156 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 157 pic24f16kl402 family 19.0 10-bit high-speed a/d converter the 10-bit a/d converter has the following key features: ? successive approximation (sar) conversion ? conversion speeds of up to 500 ksps ? up to 12 analog input pins ? external voltage reference input pins ? internal band gap reference input ? automatic channel scan mode ? selectable conversion trigger source ? two-word conversion result buffer ? selectable buffer fill modes ? four result alignment options ? operation during cpu sleep and idle modes depending on the particular device, pic24f16kl402 family devices implement up to 12 analog input pins, designated an0 through an4 and an9 through an15. in addition, there are two analog input pins for external voltage reference connections (v ref +and v ref -). these voltage reference inputs may be shared with other analog input pins. a block diagram of the a/d converter is displayed in figure 19-1 . to perform an a/d conversion: 1. configure the a/d module: a) configure port pins as analog inputs and/or select band gap reference inputs (ansa<3:0>, ansb<15:12, 4:0> and ancfg<0>). b) select the voltage reference source to match the expected range on analog inputs (ad1con2<15:13>). c) select the analog conversion clock to match the desired data rate with the processor clock (ad1con3<7:0>). d) select the appropriate sample/conversion sequence (ad1con1<7:5> and ad1con3<12:8>). e) select how conversion results are presented in the buffer (ad1con1<9:8>). f) select interrupt rate (ad1con2<5:2>). g) turn on a/d module (ad1con1<15>). 2. configure a/d interrupt (if required): a) clear the ad1if bit. b) select a/d interrupt priority. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the 10-bit high-speed a/d converter, refer to the ?pic24f family reference manual? , section 17. ?10-bit a/d converter? (ds39705).
pic24f16kl402 family ds31037b-page 158 ? 2011 microchip technology inc. figure 19-1: 10-bit high-speed a/d converter block diagram comparator 10-bit sar conversion logic v ref + dac an12 (1) an10 an11 (1) an4 (1) an0 an1 an2 (1) an3 (1) v ref - sample control s/h av ss av dd adc1buf0: adc1buf1 ad1con1 ad1con2 ad1con3 ad1chs control logic data formatting input mux control conversion control pin config control internal data bus 16 v r + v r - mux a mux b v inh v inl v inh v inh v inl v inl v bg ad1cssl v r + v r - v r select an1 an1 note 1: unimplemented in 14-pin devices. an15 an13 an14 an9
? 2011 microchip technology inc. ds31037b-page 159 pic24f16kl402 family register 19-1: ad1con1: a/d control register 1 r/w-0 u-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 adon ( 1 ) ?adsidl ? ? ?form1form0 bit 15 bit 8 r/w -0 r/w -0 r/w-0 u-0 u-0 r/w-0 r/w -0, hsc r -0, hsc ssrc2 ssrc1 ssrc0 ? ? asam samp done bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 adon: a/d operating mode bit ( 1 ) 1 = a/d converter module is operating 0 = a/d converter is off bit 14 unimplemented: read as ? 0 ? bit 13 adsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-10 unimplemented: read as ? 0 ? bit 9-8 form<1:0>: data output format bits 11 = signed fractional ( sddd dddd dd00 0000 ) 10 = fractional ( dddd dddd dd00 0000 ) 01 = signed integer ( ssss sssd dddd dddd ) 00 = integer ( 0000 00dd dddd dddd ) bit 7-5 ssrc<2:0>: conversion trigger source select bits 111 = internal counter ends sampling and starts conversion (auto-convert) 110 = reserved 101 = reserved 100 = reserved 011 = reserved 010 = timer1 compare ends sampling and starts conversion 001 = active transition on int0 pin ends sampling and starts conversion 000 = clearing the samp bit ends sampling and starts conversion bit 4-3 unimplemented: read as ? 0 ? bit 2 asam: a/d sample auto-start bit 1 = sampling begins immediately after the last conversion completes; samp bit is auto-set 0 = sampling begins when the samp bit is set bit 1 samp: a/d sample enable bit 1 = a/d sample/hold amplifier is sampling input 0 = a/d sample/hold amplifier is holding bit 0 done: a/d conversion status bit 1 = a/d conversion is done 0 = a/d conversion is not done note 1: values of adc1bufx registers will not retain their values once the adon bit is cleared. read out the conversion values from the buffer before disabling the module.
pic24f16kl402 family ds31037b-page 160 ? 2011 microchip technology inc. register 19-2: ad1con2: a/d control register 2 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 vcfg2 vcfg1 vcfg0 offcal ( 1 ) ? cscna ? ? bit 15 bit 8 r-x u-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r/w-0 ? ? smpi3 smpi2 smpi1 smpi0 ?alts bit 7 bit 0 legend: r = reserved bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 vcfg<2:0>: voltage reference configuration bits bit 12 offcal: offset calibration bit ( 1 ) 1 = conversions to get the offset calibration value 0 = conversions to get the actual input value bit 11 unimplemented: read as ? 0 ? bit 10 cscna: scan input selections for mux a input multiplexer bit 1 = scan inputs 0 = do not scan inputs bit 9-8 unimplemented: read as ? 0 ? bit 7 reserved: ignore this value bit 6 unimplemented: read as ? 0 ? bit 5-2 smpi<3:0>: sample/convert sequences per interrupt selection bits 1111 . . = reserved, do not use (may cause conversion data loss) . 0010 0001 = interrupts at the completion of conversion for each 2 nd sample/convert sequence 0000 = interrupts at the completion of conversion for each sample/convert sequence bit 1 reserved: always maintain as ? 0 ? bit 0 alts: alternate input sample mode select bit 1 = uses mux a input multiplexer settings for the first sample, then alternates between mux b and mux a input multiplexer settings for all subsequent samples 0 = always uses mux a input multiplexer settings note 1: when the offcal bit is set, inputs are disconnected and tied to av ss . this sets the inputs of the a/d to zero. then, the user can perform a conversion. use of the calibration mode is not affected by ad1pcfg contents nor channel input selection. any analog input switches are disconnected from the a/d converter in this mode. the conversion result is stored by the user software and used to compensate subsequent conversions. this can be done by adding the two?s complement of the result obtained with the offcal bit set to all normal a/d conversions. vcfg<2:0> v r +v r - 000 av dd av ss 001 external v ref + pin av ss 010 av dd external v ref - pin 011 external v ref + pin external v ref - pin 1xx av dd av ss
? 2011 microchip technology inc. ds31037b-page 161 pic24f16kl402 family register 19-3: ad1con3: a/d control register 3 r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adrc extsam pumpen samc4 samc3 samc2 samc1 samc0 bit 15 bit 8 u -0 u -0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 adrc: a/d conversion clock source bit 1 = a/d internal rc clock 0 = clock derived from system clock bit 14 extsam: extended sampling time bit 1 = a/d is still sampling after samp = 0 0 = a/d is finished sampling bit 13 pumpen: charge pump enable bit 1 = charge pump for switches is enabled 0 = charge pump for switches is disabled bit 12-8 samc<4:0>: auto-sample time bits 11111 = 31 t ad 00001 = 1 t ad 00000 = 0 t ad (not recommended) bit 7-6 unimplemented: maintain as ? 0 ? bit 5-0 adcs<5:0>: a/d conversion clock select bits 11111 = 64 ? t cy 11110 = 63 ? t cy 00001 = 2 ? t cy 00000 = t cy
pic24f16kl402 family ds31037b-page 162 ? 2011 microchip technology inc. - register 19-4: ad1chs: a/d input select register r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0nb ? ? ? ch0sb3 ch0sb2 ch0sb1 ch0sb0 bit 15 bit 8 r/w -0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0na ? ? ? ch0sa3 ch0sa2 ch0sa1 ch0sa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ch0nb: channel 0 negative input select for mux b multiplexer setting bit 1 = channel 0 negative input is an1 0 = channel 0 negative input is v r - bit 14-12 unimplemented: read as ? 0 ? bit 11-8 ch0sb<3:0>: channel 0 positive input select for mux b multiplexer setting bits 1111 = an15 1110 = an14 1101 = an13 1100 = an12 ( 1 ) 1011 = an11 ( 1 ) 1010 = an10 1001 = an9 1000 = upper guardband rail (0.785 * v dd ) 0111 = lower guardband rail (0.215 * v dd ) 0110 = internal band gap reference (v bg ) 0101 = reserved; do not use 0100 = an4 ( 1 ) 0011 = an3 ( 1 ) 0010 = an2 ( 1 ) 0001 = an1 0000 = an0 bit 7 ch0na: channel 0 negative input select for mux a multiplexer setting bit 1 = channel 0 negative input is an1 0 = channel 0 negative input is v r - bit 6-5 unimplemented: read as ? 0 ? bit 4-0 ch0sa<3:0>: channel 0 positive input select for mux a multiplexer setting bits bit combinations are identical to those for ch0sb<3:0> (above). note 1: unimplemented on 14-pin devices; do not use.
? 2011 microchip technology inc. ds31037b-page 163 pic24f16kl402 family register 19-5: ad1cssl: a/d input scan select register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cssl15 cssl14 cssl13 cssl12 ( 1 ) cssl11 ( 1 ) cssl10 cssl9 cssl8 bit 15 bit 8 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cssl7 cssl6 ? cssl4 ( 1 ) cssl3 ( 1 ) cssl2 ( 1 ) cssl1 cssl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 cssl<15:6>: a/d input pin scan selection bits ( 1 ) 1 = corresponding analog channel selected for input scan 0 = analog channel omitted from input scan bit 5 unimplemented: read as ? 0 ? bit 4-0 cssl<4:0>: a/d input pin scan selection bits ( 1 ) 1 = corresponding analog channel selected for input scan 0 = analog channel omitted from input scan note 1: these bits are unimplemented on 14-pin devices. register 19-6: ancfg: analog in put configuration register u -0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u -0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ? vbgen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-1 unimplemented: read as ? 0 ? bit 0 vbgen: internal band gap reference enable bit 1 = internal band gap voltage is available as a channel input to the a/d converter 0 = band gap is not available to the a/d converter
pic24f16kl402 family ds31037b-page 164 ? 2011 microchip technology inc. equation 19-1: a/d conversion clock period ( 1 ) figure 19-2: 10-bit a/d converter analog input model note 1: based on t cy = 2 * t osc ; doze mode and pll are disabled. t ad = t cy ? (adcs + 1) t ad t cy adcs = ? 1 c pin va rs anx v t = 0.6v v t = 0.6v i leakage r ic ? 250w sampling switch r ss c hold = dac capacitance v ss v dd = 4.4 pf (typical) 500 na legend: c pin v t i leakage r ic r ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch resistance = sample/hold capacitance (from dac) various junctions note: c pin value depends on device package and is not tested. effect of c pin negligible if rs ? 5 k ? . r ss ? 5 k ? (typical) 6-11 pf (typical)
? 2011 microchip technology inc. ds31037b-page 165 pic24f16kl402 family figure 19-3: a/d transfer function 11 1111 1111 (1023) 11 1111 1110 (1022) 10 0000 0011 (515) 10 0000 0010 (514) 10 0000 0001 (513) 10 0000 0000 (512) 01 1111 1111 (511) 01 1111 1110 (510) 01 1111 1101 (509) digital output code binary (decimal) 00 0000 0001 (1) 00 0000 0000 (0) v r - v r - + v r + - v r - 1024 v r - + 1024 512 * (v r + - v r -) voltage level v r + v r - + 1024 1023 * (v r + - v r -) v inh - v inl 0
pic24f16kl402 family ds31037b-page 166 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 167 pic24f16kl402 family 20.0 comparator module depending on the particular device, the comparator module provides one or two analog comparators. the inputs to the comparator can be configured to use any one of up to four external analog inputs, as well as a voltage reference input from either the internal band gap reference, divided by 2 (v bg /2), or the comparator voltage reference generator. the comparator outputs may be directly connected to the cxout pins. when the respective coe equals ? 1 ?, the i/o pad logic makes the unsynchronized output of the comparator available on the pin. a simplified block diagram of the module is displayed in figure 20-1 . diagrams of the possible individual comparator configurations are displayed in figure 20-2 . each comparator has its own control register, cmxcon ( register 20-1 ), for enabling and configuring its operation. the output and event status of all three comparators is provided in the cmstat register ( register 20-2 ). figure 20-1: comparator module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the comparator module, refer to the ?pic24f family reference manual? , section 19. ?dual comparator module? (ds39710). c1 v in - v in + c x inb c x inc (1) c x ina c x ind (1) cv ref v bg /2 c2 v in - v in + coe c1out pin cpol trigger/interrupt logic cevt evpol<1:0> cout input select logic cch<1:0> cref coe c2out pin cpol trigger/interrupt logic cevt evpol<1:0> cout note 1: these inputs are unavailable on 14-pin (pic24fxxkl100/200) devices. 2: comparator 2 is unimplemented on pic24fxxkl10x/20x devices. (note 2)
pic24f16kl402 family ds31037b-page 168 ? 2011 microchip technology inc. figure 20-2: individual comparator configurations cx v in - v in + off (read as ? 0 ?) comparator off con = 0 , cref = x , cch<1:0> = xx comparator cxinb > cxina compare con = 1 , cref = 0 , cch<1:0> = 00 coe cxout cx v in - v in + coe c x inb c x ina comparator cxind > cxina compare (1) con = 1 , cref = 0 , cch<1:0> = 10 cx v in - v in + coe cxout c x ind c x ina comparator cxinc > cxina compare (1) con = 1 , cref = 0 , cch<1:0> = 01 cx v in - v in + coe c x inc c x ina comparator v bg > cxina compare con = 1 , cref = 0 , cch<1:0> = 11 cx v in - v in + coe v bg /2 c x ina comparator cxinb > cv ref compare con = 1 , cref = 1 , cch<1:0> = 00 cx v in - v in + coe c x inb cv ref comparator cxind > cv ref compare (1) con = 1 , cref = 1 , cch<1:0> = 10 cx v in - v in + coe c x ind cv ref comparator cxinc > cv ref compare (1) con = 1 , cref = 1 , cch<1:0> = 01 cx v in - v in + coe c x inc cv ref comparator v bg > cv ref compare con = 1 , cref = 1 , cch<1:0> = 11 cx v in - v in + coe v bg /2 cv ref pin pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin - - - - -- - - - note 1: this configuration is unavailable on 14-pin (pic24fxxkl100/200) devices.
? 2011 microchip technology inc. ds31037b-page 169 pic24f16kl402 family register 20-1: cmxcon: comp arator x control registers r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 r-0 con coe cpol clpwr ? ? cevt cout bit 15 bit 8 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 r/w-0 r/w-0 evpol1 evpol0 ? cref ? ? cch1 cch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 con: comparator enable bit 1 = comparator is enabled 0 = comparator is disabled bit 14 coe: comparator output enable bit 1 = comparator output is present on the cxout pin 0 = comparator output is internal only bit 13 cpol: comparator output polarity select bit 1 = comparator output is inverted 0 = comparator output is not inverted bit 12 clpwr: comparator low-power mode select bit 1 = comparator operates in low-power mode 0 = comparator does not operate in low-power mode bit 11-10 unimplemented: read as ? 0 ? bit 9 cevt: comparator event bit 1 = comparator event defined by evpol<1:0> has occurred; subsequent triggers and interrupts are disabled until the bit is cleared 0 = comparator event has not occurred bit 8 cout: comparator output bit when cpol = 0 : 1 =v in + > v in - 0 =v in + < v in - when cpol = 1 : 1 =v in + < v in - 0 =v in + > v in - bit 7-6 evpol<1:0>: trigger/event/interrupt polarity select bits 11 = trigger/event/interrupt is generated on any change of the comparator output (while cevt = 0 ) 10 = trigger/event/interrupt is generated on transition of the comparator output: if cpol = 0 (non-inverted polarity): high-to-low transition only. if cpol = 1 (inverted polarity): low-to-high transition only. 01 = trigger/event/interrupt generated on transition of comparator output: if cpol = 0 (non-inverted polarity): low-to-high transition only. if cpol = 1 (inverted polarity): high-to-low transition only. 00 = trigger/event/interrupt generation is disabled bit 5 unimplemented: read as ? 0 ? note 1: unimplemented on 14-pin (pic24fxxkl100/200) devices.
pic24f16kl402 family ds31037b-page 170 ? 2011 microchip technology inc. bit 4 cref: comparator reference select bits (non-inverting input) 1 = non-inverting input connects to the internal cv ref voltage 0 = non-inverting input connects to the cxina pin bit 3-2 unimplemented: read as ? 0 ? bit 1-0 cch<1:0>: comparator channel select bits 11 = inverting input of the comparator connects to v bg /2 10 = inverting input of the comparator connects to cxind pin ( 1 ) 01 = inverting input of the comparator connects to cxinc pin ( 1 ) 00 = inverting input of the comparator connects to cxinb pin register 20-1: cmxcon: comparator x control registers (continued) note 1: unimplemented on 14-pin (pic24fxxkl100/200) devices. register 20-2: cmstat: comparat or module status register r/w-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc r-0, hsc cmidl ? ? ? ? ? c2evt ( 1 ) c1evt bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc r-0, hsc ? ? ? ? ? ?c2out ( 1 ) c1out bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 cmidl: comparator stop in idle mode bit 1 = discontinue operation of all comparators when device enters idle mode 0 = continue operation of all enabled comparators in idle mode bit 14-10 unimplemented: read as ? 0 ? bit 9 c2evt: comparator 2 event status bit (read-only) ( 1 ) shows the current event status of comparator 2 (cm2con<9>). bit 8 c1evt: comparator 1 event status bit (read-only) shows the current event status of comparator 1 (cm1con<9>). bit 7-2 unimplemented: read as ? 0 ? bit 1 c2out: comparator 2 output status bit (read-only) ( 1 ) shows the current output of comparator 2 (cm2con<8>). bit 0 c1out: comparator 1 output status bit (read-only) shows the current output of comparator 1 (cm1con<8>). note 1: these bits are unimplemented on pic24fxxkl10x/20x devices.
? 2011 microchip technology inc. ds31037b-page 171 pic24f16kl402 family 21.0 comparator voltage reference 21.1 configuring the comparator voltage reference the comparator voltage reference module is controlled through the cvrcon register ( register 21-1 ). the comparator voltage reference provides a range of output voltages, with 32 distinct levels. the comparator voltage reference supply voltage can come from either v dd and v ss , or the external v ref + and v ref -. the voltage source is selected by the cvrss bit (cvrcon<5>). the settling time of the comparator voltage reference must be considered when changing the cv ref output. figure 21-1: comparator volt age reference block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the comparator voltage reference, refer to the ?pic24f family reference manual? , section 20. ?comparator voltage reference module? (ds39709). 32-to-1 mux cvr<3:0> 8r r cvren cvrss = 0 av dd v ref + cvrss = 1 8r cvrss = 0 v ref - cvrss = 1 r r r r r r 32 steps cv ref av ss
pic24f16kl402 family ds31037b-page 172 ? 2011 microchip technology inc. register 21-1: cvrcon: comparator vo ltage reference control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe cvrss cvr4 cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 cvren: comparator voltage reference enable bit 1 =cv ref circuit is powered on 0 =cv ref circuit is powered down bit 6 cvroe: comparator v ref output enable bit 1 =cv ref voltage level is output on the cv ref pin 0 =cv ref voltage level is disconnected from the cv ref pin bit 5 cvrss: comparator v ref source selection bit 1 = comparator reference source, cv rsrc = v ref + ? v ref - 0 = comparator reference source, cv rsrc = av dd ? av ss bit 4-0 cvr<4:0>: comparator v ref value selection 0 cvr<4:0> 31 bits when cv rss = 1 : cv ref = (v ref -) + (cvr<4:0>/32) ? (v ref + ? v ref -) w hen cv rss = 0 : cv ref = (av ss ) + (cvr<4:0>/32) ? (av dd ? av ss )
? 2011 microchip technology inc. ds31037b-page 173 pic24f16kl402 family 22.0 high/low-voltage detect (hlvd) the high/low-voltage detect module (hlvd) is a programmable circuit that allows the user to specify both the device voltage trip point and the direction of change. an interrupt flag is set if the device experiences an excursion past the trip point in the direction of change. if the interrupt is enabled, the program execution will branch to the interrupt vector address and the software can then respond to the interrupt. the hlvd control register (see register 22-1 ) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. figure 22-1: high/low-voltage de tect (hlvd) module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the high/low-voltage detect, refer to the ?pic24f family reference manual? , section 36. ?high-level integration with programmable high/low-voltage detect (hlvd)? (ds39725). set v dd 16-to-1 mux hlvden hlvdl<3:0> hlvdin v dd externally generated trip point hlvdif hlvden internal voltage reference vdir 1.2v typical -
pic24f16kl402 family ds31037b-page 174 ? 2011 microchip technology inc. register 22-1: hlvdcon: high/low-v oltage detect control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 hlvden ?hlsidl ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 vdir bgvst irvst ? hlvdl3 hlvdl2 hlvdl1 hlvdl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 hlvden: high/low-voltage detect power enable bit 1 = hlvd is enabled 0 = hlvd is disabled bit 14 unimplemented: read as ? 0 ? bit 13 hlsidl: hlvd stop in idle mode bit 1 = discontinue module operation when the device enters idle mode 0 = continue module operation in idle mode bit 12-8 unimplemented: read as ? 0 ? bit 7 vdir: voltage change direction select bit 1 = event occurs when the voltage equals or exceeds the trip point (hlvdl<3:0>) 0 = event occurs when the voltage equals or falls below the trip point (hlvdl<3:0>) bit 6 bgvst: band gap voltage stable flag bit 1 = indicates that the band gap voltage is stable 0 = indicates that the band gap voltage is unstable bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the internal reference voltage is stable and the high-voltage detect logic generates the interrupt flag at the specified voltage range 0 = indicates that the internal reference voltage is unstable and the high-voltage detect logic will not generate the interrupt flag at the specified voltage range, and the hlvd interrupt should not be enabled bit 4 unimplemented: read as ? 0 ? bit 3-0 hlvdl<3:0>: high/low-voltage detection limit bits 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = trip point 14 ( 1 ) 1101 = trip point 13 ( 1 ) 1100 = trip point 12 ( 1 ) . . . 0000 = trip point 0 ( 1 ) note 1: for the actual trip point, see section 26.0 ?electrical characteristics? .
? 2011 microchip technology inc. ds31037b-page 175 pic24f16kl402 family 23.0 special features pic24f16kl402 family devices include several features intended to maximize application flexibility and reliability, and minimize cost through elimination of external components. these are: ? flexible configuration ? watchdog timer (wdt) ? code protection ? in-circuit serial programming? (icsp?) ? in-circuit emulation ? factory programmed unique id 23.1 configuration bits the configuration bits can be programmed (read as ? 0 ?), or left unprogrammed (read as ? 1 ?), to select various device configurations. these bits are mapped starting at program memory location, f80000h. a complete list is provided in table 23-1 . a detailed explanation of the various bit functions is provided in register 23-1 through register 23-7 . the address, f80000h, is beyond the user program memory space. in fact, it belongs to the configuration memory space (800000h-ffffffh), which can only be accessed using table reads and table writes. table 23-1: configuration registers locations note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the watchdog timer, high-level device inte- gration and programming diagnostics, refer to the individual sections of the ?pic24f family reference manual? provided below: ? section 9. ?watchdog timer (wdt)? (ds39697) ? section 36. ?high-level integration with programmable high/low- voltage detect (hlvd)? (ds39725) ? section 33. ?programming and diagnostics? (ds39716) configuration register address fbs f80000 fgs f80004 foscsel f80006 fosc f80008 fwdt f8000a fpor f8000c ficd f8000e
pic24f16kl402 family ds31037b-page 176 ? 2011 microchip technology inc. register 23-1: fbs: boot se gment configuration register register 23-2: fgs: general se gment configuration register u-0 u-0 u-0 u-0 r/c-1 ( 1 ) r/c-1 ( 1 ) r/c-1 ( 1 ) r/c-1 ( 1 ) ? ? ? ? bss2 bss1 bss0 bwrp bit 7 bit 0 legend: r = readable bit c = clearable only bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3-1 bss<2:0>: boot segment program flash code protection bits ( 1 ) 111 = no boot segment; all program memory space is general segment 110 = standard security boot segment starts at 0200h, ends at 0afeh 101 = standard security boot segment starts at 0200h, ends at 15feh ( 2 ) 100 = reserved 011 = reserved 010 = high-security boot segment starts at 0200h, ends at 0afeh 001 = high-security boot segment starts at 0200h, ends at 15feh ( 2 ) 000 = reserved bit 0 bwrp: boot segment program flash write protection bit ( 1 ) 1 = boot segment may be written 0 = boot segment is write-protected note 1: code protection bits can only be programmed by clearing them. they can be reset to their default factory state (? 1 ?), but only by performing a bulk erase and reprogramming the entire device. 2: this selection is available only on pic24f16kl40x devices. u-0 u-0 u-0 u-0 u-0 u-0 r/c-1 ( 1 ) r/c-1 ( 1 ) ? ? ? ? ? ? gss0 gwrp bit 7 bit 0 legend: r = readable bit c = clearable only bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1 gss0: general segment code flash code protection bit ( 1 ) 1 = no protection 0 = standard security is enabled bit 0 gwrp: general segment code flash write protection bit ( 1 ) 1 = general segment may be written 0 = general segment is write-protected note 1: code protection bits can only be programmed by clearing them. they can be reset to their default factory state (? 1 ?), but only by performing a bulk erase and reprogramming the entire device.
? 2011 microchip technology inc. ds31037b-page 177 pic24f16kl402 family register 23-3: foscsel: oscillator selection configuration register r/p-1 r/p-1 r/p-1 u-0 u-0 r/p-0 r/p-0 r/p-1 ieso lprcsel soscsrc ? ? fnosc2 fnosc1 fnosc0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ieso: internal external switchover bit 1 = internal external switchover mode is enabled (two-speed start-up is enabled) 0 = internal external switchover mode is disabled (two-speed start-up is disabled) bit 6 lprcsel: internal lprc oscillator power select bit 1 = high-power/high-accuracy mode 0 = low-power/low-accuracy mode bit 5 soscsrc: secondary oscillator clock source configuration bit 1 = sosc analog crystal function is available on the sosci/sosco pins 0 = sosc crystal is disabled; digital sclki function is selected on the sosco pin bit 4-3 unimplemented: read as ? 0 ? bit 2-0 fnosc<2:0>: oscillator selection bits 111 = 8 mhz frc oscillator with divide-by-n (frcdiv) 110 = 500 khz low-power frc oscillator with divide-by-n (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (hs+pll, ec+pll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with divide-by-n with pll module (frcdiv+pll) 000 = 8 mhz frc oscillator (frc)
pic24f16kl402 family ds31037b-page 178 ? 2011 microchip technology inc. register 23-4: fosc: oscilla tor configuration register r/p-0 r/p-0 r/p-1 r/p-1 r/p-1 r/p-0 r/p-1 r/p-1 fcksm1 fcksm0 soscsel poscfreq1 poscfreq0 osciofnc poscmd1 poscmd0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fcksm<1:0>: clock switching and monitor selection configuration bits 1x = clock switching is disabled, fail-safe clock monitor is disabled 01 = clock switching is enabled, fail-safe clock monitor is disabled 00 = clock switching is enabled, fail-safe clock monitor is enabled bit 5 soscsel: secondary oscillator power selection configuration bit 1 = secondary oscillator is configured for high-power operation 0 = secondary oscillator is configured for low-power operation bit 4-3 poscfreq<1:0>: primary oscillator frequency range configuration bits 11 = primary oscillator/external clock input frequency is greater than 8 mhz 10 = primary oscillator/external clock input frequency is between 100 khz and 8 mhz 01 = primary oscillator/external clock input frequency is less than 100 khz 00 = reserved; do not use bit 2 osciofnc: clko enable configuration bit 1 = clko output signal is active on the osco pin; primary oscillator must be disabled or configured for the external clock mode (ec) for the clko to be active (poscmd<1:0> = 11 or 00 ) 0 = clko output is disabled bit 1-0 poscmd<1:0>: primary oscillator configuration bits 11 = primary oscillator mode is disabled 10 = hs oscillator mode is selected 01 = xt oscillator mode is selected 00 = external clock mode is selected
? 2011 microchip technology inc. ds31037b-page 179 pic24f16kl402 family register 23-5: fwdt: watchdog timer configuration register r/p-1 r/p-1 r/p-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 fwdten1 windis fwdten0 fwpsa wdtps3 wdtps2 wdtps1 wdtps0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7,5 fwdten<1:0>: watchdog timer enable bit 11 = wdt is enabled in hardware 10 = wdt is controlled with the swdten bit setting 01 = wdt is enabled only while device is active; wdt is disabled in sleep; swdten bit is disabled 00 = wdt is disabled in hardware; swdten bit is disabled bit 6 windis: windowed watchdog timer disable bit 1 = standard wdt is selected; windowed wdt is disabled 0 = windowed wdt is enabled; note that executing a clrwdt instruction while the wdt is disabled in hardware and software (fwdten<1:0> = 00 and rcon bit, swdten = 0 ) will not cause a device reset bit 4 fwpsa: wdt prescaler bit 1 = wdt prescaler ratio of 1:128 0 = wdt prescaler ratio of 1:32 bit 3-0 wdtps<3:0>: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1
pic24f16kl402 family ds31037b-page 180 ? 2011 microchip technology inc. register 23-6: fpor: rese t configuration register r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 u-0 r/p-1 r/p-1 mclre ( 1 ) borv1 ( 2 ) borv0 ( 2 ) i2c1sel ( 3 ) pwrten ? boren1 boren0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mclre: mclr pin enable bit ( 1 ) 1 = mclr pin is enabled; ra5 input pin is disabled 0 = ra5 input pin is enabled; mclr is disabled bit 6-5 borv<1:0>: brown-out reset enable bits ( 2 ) 11 = brown-out reset is set to the low trip point 10 = brown-out reset is set to the middle trip point 01 = brown-out reset is set to the high trip point 00 = downside protection on por is enabled (low-power bor is selected) bit 4 i2c1sel: alternate mssp1 i 2 c? pin mapping bit ( 3 ) 1 = default location for scl1/sda1 pins (rb8 and rb9) 0 = alternate location for scl1/sda1 pins (ascl1/rb6 and asda1/rb5) bit 3 pwrten: power-up timer enable bit 1 = pwrt is enabled 0 = pwrt is disabled bit 2 unimplemented: read as ? 0 ? bit 1-0 boren<1:0>: brown-out reset enable bits 11 = bor is enabled in hardware; sboren bit is disabled 10 = bor is enabled only while device is active and disabled in sleep; sboren bit is disabled 01 = bor is controlled with the sboren bit setting 00 = bor is disabled in hardware; sboren bit is disabled note 1: the mclre fuse can only be changed when using the v pp -based icsp? mode entry. this prevents a user from accidentally locking out the device from the low-voltage test entry. 2: refer to table 26-5 for bor trip point voltages. 3: implemented in 28-pin devices only. this bit position must be programmed (= 1 ) in all other devices for i 2 c functionality to be available.
? 2011 microchip technology inc. ds31037b-page 181 pic24f16kl402 family register 23-7: ficd: in-circuit debugger configuration register 23.2 unique id a read-only unique id value is stored at addresses, 800802h through 800808h. this factory programmed value is unique to each microcontroller produced in the pic24f16kl402 family. to access this region, use table read instructions or program space visibility. to ensure a globally unique id across other microchip microcontroller families, the ?unique id? value should be further concatenated with the family and device id values stored at address, ff0000h. r/p-1 u-1 u-1 u-0 u-0 u-0 r/p-1 r/p-1 debug ? ? ? ? ? ics1 ics0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 debug : background debugger enable bit 1 = background debugger is disabled 0 = background debugger functions are enabled bit 6-5 unimplemented: read as ? 1 ? bit 4-2 unimplemented: read as ? 0 ? bit 1-0 ics<1:0:> icd pin select bits 11 = pgec1/pged1 are used for programming and debugging the device ( 1 ) 10 = pgec2/pged2 are used for programming and debugging the device 01 = pgec3/pged3 are used for programming and debugging the device 00 = reserved; do not use note 1: pgec1/pged1 are not available on PIC24F04KL100 (14-pin) devices.
pic24f16kl402 family ds31037b-page 182 ? 2011 microchip technology inc. register 23-8: devid: device id register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 23 bit 16 rrrrrrrr famid7 famid6 famid5 famid4 famid3 famid2 famid1 famid0 bit 15 bit 8 rrrrrrrr dev7 dev6 dev5 dev4 dev3 dev2 dev1 dev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 23-16 unimplemented: read as ? 0 ? bit 15-8 famid<7:0>: device family identifier bits 01001011 = pic24f16kl402 family bit 7-0 dev<7:0>: individual device identifier bits 00000001 = PIC24F04KL100 00000010 = pic24f04kl101 00000101 = pic24f08kl200 00000110 = pic24f08kl201 00001010 = pic24f08kl301 00000000 = pic24f08kl302 00001110 = pic24f08kl401 00000100 = pic24f08kl402 00011110 = pic24f16kl401 00010100 = pic24f16kl402
? 2011 microchip technology inc. ds31037b-page 183 pic24f16kl402 family register 23-9: devrev: device revision register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 23 bit 16 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r r r r ? ? ? ? rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 23-4 unimplemented: read as ? 0 ? bit 3-0 rev<3:0>: revision identifier bits
pic24f16kl402 family ds31037b-page 184 ? 2011 microchip technology inc. 23.3 watchdog timer (wdt) for the pic24f16kl402 family of devices, the wdt is driven by the lprc oscillator. when the wdt is enabled, the clock source is also enabled. the nominal wdt clock source from lprc is 31 khz. this feeds a prescaler that can be configured for either 5-bit (divide-by-32) or 7-bit (divide-by-128) operation. the prescaler is set by the fwpsa configuration bit. with a 31 khz input, the prescaler yields a nominal wdt time-out period (t wdt ) of 1 ms in 5-bit mode or 4 ms in 7-bit mode. a variable postscaler divides down the wdt prescaler output and allows for a wide range of time-out periods. the postscaler is controlled by the configuration bits, wdtps<3:0> (fwdt<3:0>), which allow the selection of a total of 16 settings, from 1:1 to 1:32,768. using the prescaler and postscaler time-out periods, ranges from 1 ms to 131 seconds can be achieved. the wdt, prescaler and postscaler are reset: ? on any device reset ? on the completion of a clock switch, whether invoked by software (i.e., setting the oswen bit after changing the nosc bits) or by hardware (i.e., fail-safe clock monitor) ? when a pwrsav instruction is executed (i.e., sleep or idle mode is entered) ? when the device exits sleep or idle mode to resume normal operation ?by a clrwdt instruction during normal execution if the wdt is enabled in hardware (fwdten<1:0> = 11 ), it will continue to run during sleep or idle modes. when the wdt time-out occurs, the device will wake and code execution will continue from where the pwrsav instruction was executed. the corresponding sleep or idle bits (rcon<3:2>) will need to be cleared in software after the device wakes up. the wdt flag bit, wdto (rcon<4>), is not automatically cleared following a wdt time-out. to detect subsequent wdt events, the flag must be cleared in software. 23.3.1 windowed operation the watchdog timer has an optional fixed window mode of operation. in this windowed mode, clrwdt instructions can only reset the wdt during the last 1/4 of the programmed wdt period. a clrwdt instruction, executed before that window, causes a wdt reset similar to a wdt time-out. windowed wdt mode is enabled by programming the configuration bit, windis (fwdt<6>), to ? 0 ?. 23.3.2 control register the wdt is enabled or disabled by the fwdten<1:0> configuration bits. when both the fwdten<1:0> con- figuration bits are set, the wdt is always enabled. the wdt can be optionally controlled in software when the fwdten<1:0> configuration bits have been pro- grammed to ? 10 ?. the wdt is enabled in software by setting the swdten control bit (rcon<5>). the swdten control bit is cleared on any device reset. the software wdt option allows the user to enable the wdt for critical code segments, and disable the wdt during non-critical segments, for maximum power sav- ings. when the fwten<1:0> bits are set to ? 01 ?, the wdt is enabled only in run and idle modes, and is dis- abled in sleep. software control of the wdt swdten bit (rcon<5>) is disabled with this setting. figure 23-1: wdt block diagram note: the clrwdt and pwrsav instructions clear the prescaler and postscaler counts when executed. lprc input wdt overflow wake from sleep 31 khz prescaler postscaler fwpsa swdten fwdten reset all device resets sleep or idle mode lprc control clrwdt instr. pwrsav instr. (5-bit/7-bit) 1:1 to 1:32.768 wdtps<3:0> 1 ms/4 ms exit sleep or idle mode wdt counter transition to new clock source
? 2011 microchip technology inc. ds31037b-page 185 pic24f16kl402 family 23.4 program verification and code protection for all devices in the pic24f16kl402 family, code protection for the boot segment is controlled by the bss<2:0> configuration bits and the general segment by the configuration bit, gss0. these bits inhibit exter- nal reads and writes to the program memory space this has no direct effect in normal execution mode. write protection is controlled by bit, bwrp, for the boot segment and bit, gwrp, for the general segment in the configuration word. when these bits are programmed to ? 0 ?, internal write and erase operations to program memory are blocked. 23.5 in-circuit serial programming pic24f16kl402 family microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock (pgecx) and data (pgedx), and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. 23.6 in-circuit debugger when mplab ? icd 3, mplab real ice? or pickit? 3 is selected as a debugger, the in-circuit debugging functionality is enabled. this function allows simple debugging functions when used with mplab ide. debugging functionality is controlled through the pgecx and pgedx pins. to use the in-circuit debugger function of the device, the design must implement icsp connections to mclr , v dd , v ss , pgecx, pgedx and the pin pair. in addition, when the feature is enabled, some of the resources are not available for general use. these resources include the first 80 bytes of data ram and two i/o pins.
pic24f16kl402 family ds31037b-page 186 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 187 pic24f16kl402 family 24.0 development support the pic ? microcontrollers and dspic ? digital signal controllers are supported with a full range of software and hardware development tools: ? integrated development environment - mplab ? ide software ? compilers/assemblers/linkers - mplab c compiler for various device families - hi-tech c ? for various device families - mpasm tm assembler -mplink tm object linker/ mplib tm object librarian - mplab assembler/linker/librarian for various device families ? simulators - mplab sim software simulator ?emulators - mplab real ice? in-circuit emulator ? in-circuit debuggers - mplab icd 3 - pickit? 3 debug express ? device programmers - pickit? 2 programmer - mplab pm3 device programmer ? low-cost demonstration/development boards, evaluation kits, and starter kits 24.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16/32-bit microcontroller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - in-circuit emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as iar c compilers the mplab ide allows you to: ? edit your source files (either c or assembly) ? one-touch compile or assemble, and download to emulator and simulator tools (automatically updates all project information) ? debug using: - source files (c or assembly) - mixed c and assembly - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic24f16kl402 family ds31037b-page 188 ? 2011 microchip technology inc. 24.2 mplab c compilers for various device families the mplab c compiler code development systems are complete ansi c compilers for microchip?s pic18, pic24 and pic32 families of microcontrollers and the dspic30 and dspic33 families of digital signal control- lers. these compilers provide powerful integration capabilities, superior code optimization and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 24.3 hi-tech c for various device families the hi-tech c compiler code development systems are complete ansi c compilers for microchip?s pic family of microcontrollers and the dspic family of digital signal controllers. these compilers provide powerful integration capabilities, omniscient code generation and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. the compilers include a macro assembler, linker, pre- processor, and one-step driver, and can run on multiple platforms. 24.4 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for pic10/12/16/18 mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 24.5 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 24.6 mplab assembler, linker and librarian for various device families mplab assembler produces relocatable machine code from symbolic assembly language for pic24, pic32 and dspic devices. mplab c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire device instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility
? 2011 microchip technology inc. ds31037b-page 189 pic24f16kl402 family 24.7 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c compilers, and the mpasm and mplab assemblers. the soft- ware simulator offers the flexibility to develop and debug code outside of the hardware laboratory envi- ronment, making it an excellent, economical software development tool. 24.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the emulator is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with in- circuit debugger systems (rj11) or with the new high- speed, noise tolerant, low-voltage differential signal (lvds) interconnection (cat5). the emulator is field upgradable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, run-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 24.9 mplab icd 3 in-circuit debugger system mplab icd 3 in-circuit debugger system is micro- chip's most cost effective high-speed hardware debugger/programmer for microchip flash digital sig- nal controller (dsc) and microcontroller (mcu) devices. it debugs and programs pic ? flash microcon- trollers and dspic ? dscs with the powerful, yet easy- to-use graphical user interface of mplab integrated development environment (ide). the mplab icd 3 in-circuit debugger probe is con- nected to the design engineer's pc using a high-speed usb 2.0 interface and is connected to the target with a connector compatible with the mplab icd 2 or mplab real ice systems (rj-11). mplab icd 3 supports all mplab icd 2 headers. 24.10 pickit 3 in-circuit debugger/ programmer and pickit 3 debug express the mplab pickit 3 allows debugging and program- ming of pic ? and dspic ? flash microcontrollers at a most affordable price point using the powerful graphical user interface of the mplab integrated development environment (ide). the mplab pickit 3 is connected to the design engineer's pc using a full speed usb interface and can be connected to the target via an microchip debug (rj-11) connector (compatible with mplab icd 3 and mplab real ice). the connector uses two device i/o pins and the reset line to imple- ment in-circuit debugging and in-circuit serial pro- gramming?. the pickit 3 debug express include the pickit 3, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software.
pic24f16kl402 family ds31037b-page 190 ? 2011 microchip technology inc. 24.11 pickit 2 development programmer/debugger and pickit 2 debug express the pickit? 2 development programmer/debugger is a low-cost development tool with an easy to use inter- face for programming and debugging microchip?s flash families of microcontrollers. the full featured windows ? programming interface supports baseline (pic10f, pic12f5xx, pic16f5xx), midrange (pic12f6xx, pic16f), pic18f, pic24, dspic30, dspic33, and pic32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many microchip serial eeprom products. with microchip?s powerful mplab integrated development environment (ide) the pickit? 2 enables in-circuit debugging on most pic ? microcon- trollers. in-circuit-debugging runs, halts and single steps the program while the pic microcontroller is embedded in the application. when halted at a break- point, the file registers can be examined and modified. the pickit 2 debug express include the pickit 2, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software. 24.12 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an mmc card for file storage and data applications. 24.13 demonstration/development boards, evaluation kits, and starter kits a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. also available are starter kits that contain everything needed to experience the specified device. this usually includes a single application and debug capability, all on one board. check the microchip web page ( www.microchip.com ) for the complete list of demonstration, development and evaluation kits.
? 2011 microchip technology inc. ds31037b-page 191 pic24f16kl402 family 25.0 instruction set summary the pic24f instruction set adds many enhancements to the previous pic ? mcu instruction sets, while maintaining an easy migration from previous pic mcu instruction sets. most instructions are a single program memory word. only three instructions require two program memory locations. each single-word instruction is a 24-bit word divided into an 8-bit opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? word or byte-oriented operations ? bit-oriented operations ? literal operations ? control operations table 25-1 lists the general symbols used in describing the instructions. the pic24f instruction set summary in tab l e 2 5- 2 lists all the instructions, along with the status flags affected by each instruction. most word or byte-oriented w register instructions (including barrel shift instructions) have three operands: ? the first source operand, which is typically a register ?wb? without any address modifier ? the second source operand, which is typically a register ?ws? with or without an address modifier ? the destination of the result, which is typically a register ?wd? with or without an address modifier however, word or byte-oriented file register instructions have two operands: ? the file register specified by the value, ?f? ? the destination, which could either be the file register, ?f?, or the w0 register, which is denoted as ?wreg? most bit-oriented instructions (including simple rotate/shift instructions) have two operands: ? the w register (with or without an address modifier) or file register (specified by the value of ?ws? or ?f?) ? the bit in the w register or file register (specified by a literal value or indirectly by the contents of register ?wb?) the literal instructions that involve data movement may use some of the following operands: ? a literal value to be loaded into a w register or file register (specified by the value of ?k?) ? the w register or file register where the literal value is to be loaded (specified by ?wb? or ?f?) however, literal instructions that involve arithmetic or logical operations use some of the following operands: ? the first source operand, which is a register ?wb? without any address modifier ? the second source operand, which is a literal value ? the destination of the result (only if not the same as the first source operand), which is typically a register ?wd? with or without an address modifier the control instructions may use some of the following operands: ? a program memory address ? the mode of the table read and table write instructions all instructions are a single word, except for certain double-word instructions, which were made double-word instructions so that all of the required information is available in these 48 bits. in the second word, the 8 msbs are ? 0 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . most single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter (pc) is changed as a result of the instruction. in these cases, the execution takes two instruction cycles, with the additional instruction cycle(s) executed as a nop . notable exceptions are the bra (unconditional/computed branch), indirect call/goto , all table reads and writes, and return/retfie instructions, which are single-word instructions but take two or three cycles. certain instructions that involve skipping over the subsequent instruction require either two or three cycles if the skip is performed, depending on whether the instruction being skipped is a single-word or two-word instruction. moreover, double-word moves require two cycles. the double-word instructions execute in two instruction cycles. note: this chapter is a brief summary of the pic24f instruction set architecture (isa) and is not intended to be a comprehensive reference source.
pic24f16kl402 family ds31037b-page 192 ? 2011 microchip technology inc. table 25-1: symbols used in opcode descriptions field description #text means literal defined by ? text ? (text) means ?content of text ? [text] means ?the location addressed by text ? { } optional field or operation register bit field .b byte mode selection .d double-word mode selection .s shadow register select .w word mode selection (default) bit4 4-bit bit selection field (used in word addressed instructions) ?? {0...15} c, dc, n, ov, z mcu status bits: carry, digit carry, negative, overflow, sticky zero expr absolute address, label or expression (resolved by the linker) f file register address ?? {0000h...1fffh} lit1 1-bit unsigned literal ?? {0,1} lit4 4-bit unsigned literal ?? {0...15} lit5 5-bit unsigned literal ?? {0...31} lit8 8-bit unsigned literal ?? {0...255} lit10 10-bit unsigned literal ?? {0...255} for byte mode, {0:1023} for word mode lit14 14-bit unsigned literal ?? {0...16384} lit16 16-bit unsigned literal ?? {0...65535} lit23 23-bit unsigned literal ?? {0...8388608}; lsb must be ? 0 ? none field does not require an entry, may be blank pc program counter slit10 10-bit signed literal ?? {-512...511} slit16 16-bit signed literal ?? {-32768...32767} slit6 6-bit signed literal ?? {-16...16} wb base w register ?? {w0..w15} wd destination w register ?? { wd, [wd], [wd++], [wd--], [++wd], [--wd] } wdo destination w register ? { wnd, [wnd], [wnd++], [wnd--], [++wnd], [--wnd], [wnd+wb] } wm,wn dividend, divisor working r egister pair (direct addressing) wn one of 16 working registers ?? {w0..w15} wnd one of 16 destination working registers ?? {w0..w15} wns one of 16 source working registers ?? {w0..w15} wreg w0 (working register used in file register instructions) ws source w register ?? { ws, [ws], [ws++], [ws--], [++ws], [--ws] } wso source w register ?? { wns, [wns], [wns++], [wns--], [++wns], [--wns], [wns+wb] }
? 2011 microchip technology inc. ds31037b-page 193 pic24f16kl402 family table 25-2: instruction set overview assembly mnemonic assembly syntax description # of words # of cycles status flags affected add add f f = f + wreg 1 1 c, dc, n, ov, z add f,wreg wreg = f + wreg 1 1 c, dc, n, ov, z add #lit10,wn wd = lit10 + wd 1 1 c, dc, n, ov, z add wb,ws,wd wd = wb + ws 1 1 c, dc, n, ov, z add wb,#lit5,wd wd = wb + lit5 1 1 c, dc, n, ov, z addc addc f f = f + wreg + (c) 1 1 c, dc, n, ov, z addc f,wreg wreg = f + wreg + (c) 1 1 c, dc, n, ov, z addc #lit10,wn wd = lit10 + wd + (c) 1 1 c, dc, n, ov, z addc wb,ws,wd wd = wb + ws + (c) 1 1 c, dc, n, ov, z addc wb,#lit5,wd wd = wb + lit5 + (c) 1 1 c, dc, n, ov, z and and f f = f .and. wreg 1 1 n, z and f,wreg wreg = f .and. wreg 1 1 n, z and #lit10,wn wd = lit10 .and. wd 1 1 n, z and wb,ws,wd wd = wb .and. ws 1 1 n, z and wb,#lit5,wd wd = wb .and. lit5 1 1 n, z asr asr f f = arithmetic right shift f 1 1 c, n, ov, z asr f,wreg wreg = arithmetic right shift f 1 1 c, n, ov, z asr ws,wd wd = arithmetic right shift ws 1 1 c, n, ov, z asr wb,wns,wnd wnd = arithmetic right shift wb by wns 1 1 n, z asr wb,#lit5,wnd wnd = arithmetic right shift wb by lit5 1 1 n, z bclr bclr f,#bit4 bit clear f 1 1 none bclr ws,#bit4 bit clear ws 1 1 none bra bra c,expr branch if carry 1 1 (2) none bra ge,expr branch if greater than or equal 1 1 (2) none bra geu,expr branch if unsigned greater than or equal 1 1 (2) none bra gt,expr branch if greater than 1 1 (2) none bra gtu,expr branch if unsigned greater than 1 1 (2) none bra le,expr branch if less than or equal 1 1 (2) none bra leu,expr branch if unsigned less than or equal 1 1 (2) none bra lt,expr branch if less than 1 1 (2) none bra ltu,expr branch if unsigned less than 1 1 (2) none bra n,expr branch if negative 1 1 (2) none bra nc,expr branch if not carry 1 1 (2) none bra nn,expr branch if not negative 1 1 (2) none bra nov,expr branch if not overflow 1 1 (2) none bra nz,expr branch if not zero 1 1 (2) none bra ov,expr branch if overflow 1 1 (2) none bra expr branch unconditionally 1 2 none bra z,expr branch if zero 1 1 (2) none bra wn computed branch 1 2 none bset bset f,#bit4 bit set f 1 1 none bset ws,#bit4 bit set ws 1 1 none bsw bsw.c ws,wb write c bit to ws 1 1 none bsw.z ws,wb write z bit to ws 1 1 none btg btg f,#bit4 bit toggle f 1 1 none btg ws,#bit4 bit toggle ws 1 1 none btsc btsc f,#bit4 bit test f, skip if clear 1 1 (2 or 3) none btsc ws,#bit4 bit test ws, skip if clear 1 1 (2 or 3) none
pic24f16kl402 family ds31037b-page 194 ? 2011 microchip technology inc. btss btss f,#bit4 bit test f, skip if set 1 1 (2 or 3) none btss ws,#bit4 bit test ws, skip if set 1 1 (2 or 3) none btst btst f,#bit4 bit test f 1 1 z btst.c ws,#bit4 bit test ws to c 1 1 c btst.z ws,#bit4 bit test ws to z 1 1 z btst.c ws,wb bit test ws to c 1 1 c btst.z ws,wb bit test ws to z 1 1 z btsts btsts f,#bit4 bit test then set f 1 1 z btsts.c ws,#bit4 bit test ws to c, then set 1 1 c btsts.z ws,#bit4 bit test ws to z, then set 1 1 z call call lit23 call subroutine 2 2 none call wn call indirect subroutine 1 2 none clr clr f f = 0x0000 1 1 none clr wreg wreg = 0x0000 1 1 none clr ws ws = 0x0000 1 1 none clrwdt clrwdt clear watchdog timer 1 1 wdto, sleep com com f f = f 11n, z com f,wreg wreg = f 11n, z com ws,wd wd = ws 11n, z cp cp f compare f with wreg 1 1 c, dc, n, ov, z cp wb,#lit5 compare wb with lit5 1 1 c, dc, n, ov, z cp wb,ws compare wb with ws (wb ? ws) 1 1 c, dc, n, ov, z cp0 cp0 f compare f with 0x0000 1 1 c, dc, n, ov, z cp0 ws compare ws with 0x0000 1 1 c, dc, n, ov, z cpb cpb f compare f with wreg, with borrow 1 1 c, dc, n, ov, z cpb wb,#lit5 compare wb with lit5, with borrow 1 1 c, dc, n, ov, z cpb wb,ws compare wb with ws, with borrow (wb ? ws ? c ) 1 1 c, dc, n, ov, z cpseq cpseq wb,wn compare wb with wn, skip if = 1 1 (2 or 3) none cpsgt cpsgt wb,wn compare wb with wn, skip if > 1 1 (2 or 3) none cpslt cpslt wb,wn compare wb with wn, skip if < 1 1 (2 or 3) none cpsne cpsne wb,wn compare wb with wn, skip if ? 11 (2 or 3) none daw daw.b wn wn = decimal adjust wn 1 1 c dec dec f f = f ?1 1 1 c, dc, n, ov, z dec f,wreg wreg = f ?1 1 1 c, dc, n, ov, z dec ws,wd wd = ws ? 1 1 1 c, dc, n, ov, z dec2 dec2 f f = f ? 2 1 1 c, dc, n, ov, z dec2 f,wreg wreg = f ? 2 1 1 c, dc, n, ov, z dec2 ws,wd wd = ws ? 2 1 1 c, dc, n, ov, z disi disi #lit14 disable interrupts for k instruction cycles 1 1 none div div.sw wm,wn signed 16/16-bit integer divide 1 18 n, z, c, ov div.sd wm,wn signed 32/16-bit integer divide 1 18 n, z, c, ov div.uw wm,wn unsigned 16/16-bit integer divide 1 18 n, z, c, ov div.ud wm,wn unsigned 32/16-bit integer divide 1 18 n, z, c, ov exch exch wns,wnd swap wns with wnd 1 1 none ff1l ff1l ws,wnd find first one from left (msb) side 1 1 c ff1r ff1r ws,wnd find first one from right (lsb) side 1 1 c table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
? 2011 microchip technology inc. ds31037b-page 195 pic24f16kl402 family goto goto expr go to address 2 2 none goto wn go to indirect 1 2 none inc inc f f = f + 1 1 1 c, dc, n, ov, z inc f,wreg wreg = f + 1 1 1 c, dc, n, ov, z inc ws,wd wd = ws + 1 1 1 c, dc, n, ov, z inc2 inc2 f f = f + 2 1 1 c, dc, n, ov, z inc2 f,wreg wreg = f + 2 1 1 c, dc, n, ov, z inc2 ws,wd wd = ws + 2 1 1 c, dc, n, ov, z ior ior f f = f .ior. wreg 1 1 n, z ior f,wreg wreg = f .ior. wreg 1 1 n, z ior #lit10,wn wd = lit10 .ior. wd 1 1 n, z ior wb,ws,wd wd = wb .ior. ws 1 1 n, z ior wb,#lit5,wd wd = wb .ior. lit5 1 1 n, z lnk lnk #lit14 link frame pointer 1 1 none lsr lsr f f = logical right shift f 1 1 c, n, ov, z lsr f,wreg wreg = logical right shift f 1 1 c, n, ov, z lsr ws,wd wd = logical right shift ws 1 1 c, n, ov, z lsr wb,wns,wnd wnd = logical right shift wb by wns 1 1 n, z lsr wb,#lit5,wnd wnd = logical right shift wb by lit5 1 1 n, z mov mov f,wn move f to wn 1 1 none mov [wns+slit10],wnd move [wns+slit10] to wnd 1 1 none mov f move f to f 1 1 n, z mov f,wreg move f to wreg 1 1 none mov #lit16,wn move 16-bit literal to wn 1 1 none mov.b #lit8,wn move 8-bit literal to wn 1 1 none mov wn,f move wn to f 1 1 none mov wns,[wns+slit10] move wns to [wns+slit10] 1 1 none mov wso,wdo move ws to wd 1 1 none mov wreg,f move wreg to f 1 1 none mov.d wns,wd move double from w(ns):w(ns+1) to wd 1 2 none mov.d ws,wnd move double from ws to w(nd+1):w(nd) 1 2 none mul mul.ss wb,ws,wnd {wnd+1, wnd} = signed(wb) * signed(ws) 1 1 none mul.su wb,ws,wnd {wnd+1, wnd} = signed(wb) * unsigned(ws) 1 1 none mul.us wb,ws,wnd {wnd+1, wnd} = unsigned(wb) * signed(ws) 1 1 none mul.uu wb,ws,wnd {wnd+1, wnd} = unsigned(wb) * unsigned(ws) 1 1 none mul.su wb,#lit5,wnd {wnd+1, wnd} = signed(wb) * unsigned(lit5) 1 1 none mul.uu wb,#lit5,wnd {wnd+1, wnd} = unsigned(wb) * unsigned(lit5) 1 1 none mul f w3:w2 = f * wreg 1 1 none neg neg f f = f + 1 1 1 c, dc, n, ov, z neg f,wreg wreg = f + 1 1 1 c, dc, n, ov, z neg ws,wd wd = ws + 1 1 1 c, dc, n, ov, z nop nop no operation 1 1 none nopr no operation 1 1 none pop pop f pop f from top-of-stack (tos) 1 1 none pop wdo pop from top-of-stack (tos) to wdo 1 1 none pop.d wnd pop from top-of-stack (tos) to w(nd):w(nd+1) 1 2 none pop.s pop shadow registers 1 1 all push push f push f to top-of-stack (tos) 1 1 none push wso push wso to top-of-stack (tos) 1 1 none push.d wns push w(ns):w(ns+1) to top-of-stack (tos) 1 2 none push.s push shadow registers 1 1 none table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
pic24f16kl402 family ds31037b-page 196 ? 2011 microchip technology inc. pwrsav pwrsav #lit1 go into sleep or idle mode 1 1 wdto, sleep rcall rcall expr relative call 1 2 none rcall wn computed call 1 2 none repeat repeat #lit14 repeat next instruction lit14 + 1 times 1 1 none repeat wn repeat next instruction (wn) + 1 times 1 1 none reset reset software device reset 1 1 none retfie retfie return from interrupt 1 3 (2) none retlw retlw #lit10,wn return with literal in wn 1 3 (2) none return return return from subroutine 1 3 (2) none rlc rlc f f = rotate left through carry f 1 1 c, n, z rlc f,wreg wreg = rotate left through carry f 1 1 c, n, z rlc ws,wd wd = rotate left through carry ws 1 1 c, n, z rlnc rlnc f f = rotate left (no carry) f 1 1 n, z rlnc f,wreg wreg = rotate left (no carry) f 1 1 n, z rlnc ws,wd wd = rotate left (no carry) ws 1 1 n, z rrc rrc f f = rotate right through carry f 1 1 c, n, z rrc f,wreg wreg = rotate right through carry f 1 1 c, n, z rrc ws,wd wd = rotate right through carry ws 1 1 c, n, z rrnc rrnc f f = rotate right (no carry) f 1 1 n, z rrnc f,wreg wreg = rotate right (no carry) f 1 1 n, z rrnc ws,wd wd = rotate right (no carry) ws 1 1 n, z se se ws,wnd wnd = sign-extended ws 1 1 c, n, z setm setm f f = ffffh 1 1 none setm wreg wreg = ffffh 1 1 none setm ws ws = ffffh 1 1 none sl sl f f = left shift f 1 1 c, n, ov, z sl f,wreg wreg = left shift f 1 1 c, n, ov, z sl ws,wd wd = left shift ws 1 1 c, n, ov, z sl wb,wns,wnd wnd = left shift wb by wns 1 1 n, z sl wb,#lit5,wnd wnd = left shift wb by lit5 1 1 n, z sub sub f f = f ? wreg 1 1 c, dc, n, ov, z sub f,wreg wreg = f ? wreg 1 1 c, dc, n, ov, z sub #lit10,wn wn = wn ? lit10 1 1 c, dc, n, ov, z sub wb,ws,wd wd = wb ? ws 1 1 c, dc, n, ov, z sub wb,#lit5,wd wd = wb ? lit5 1 1 c, dc, n, ov, z subb subb f f = f ? wreg ? (c ) 1 1 c, dc, n, ov, z subb f,wreg wreg = f ? wreg ? (c ) 1 1 c, dc, n, ov, z subb #lit10,wn wn = wn ? lit10 ? (c ) 1 1 c, dc, n, ov, z subb wb,ws,wd wd = wb ? ws ? (c ) 1 1 c, dc, n, ov, z subb wb,#lit5,wd wd = wb ? lit5 ? (c ) 1 1 c, dc, n, ov, z subr subr f f = wreg ? f 1 1 c, dc, n, ov, z subr f,wreg wreg = wreg ? f 1 1 c, dc, n, ov, z subr wb,ws,wd wd = ws ? wb 1 1 c, dc, n, ov, z subr wb,#lit5,wd wd = lit5 ? wb 1 1 c, dc, n, ov, z subbr subbr f f = wreg ? f ? (c ) 1 1 c, dc, n, ov, z subbr f,wreg wreg = wreg ? f ? (c ) 1 1 c, dc, n, ov, z subbr wb,ws,wd wd = ws ? wb ? (c ) 1 1 c, dc, n, ov, z subbr wb,#lit5,wd wd = lit5 ? wb ? (c ) 1 1 c, dc, n, ov, z swap swap.b wn wn = nibble swap wn 1 1 none swap wn wn = byte swap wn 1 1 none tblrdh tblrdh ws,wd read prog<23:16> to wd<7:0> 1 2 none table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
? 2011 microchip technology inc. ds31037b-page 197 pic24f16kl402 family tblrdl tblrdl ws,wd read prog<15:0> to wd 1 2 none tblwth tblwth ws,wd write ws<7:0> to prog<23:16> 1 2 none tblwtl tblwtl ws,wd write ws to prog<15:0> 1 2 none ulnk ulnk unlink frame pointer 1 1 none xor xor f f = f .xor. wreg 1 1 n, z xor f,wreg wreg = f .xor. wreg 1 1 n, z xor #lit10,wn wd = lit10 .xor. wd 1 1 n, z xor wb,ws,wd wd = wb .xor. ws 1 1 n, z xor wb,#lit5,wd wd = wb .xor. lit5 1 1 n, z ze ze ws,wnd wnd = zero-extend ws 1 1 c, z, n table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
pic24f16kl402 family ds31037b-page 198 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 199 pic24f16kl402 family 26.0 electrical characteristics this section provides an overview of the pic24f16kl402 family electrical characteristics. additional information will be provided in future revisions of this document as it becomes available. absolute maximum ratings for the pic24f16kl402 family are listed below. exposure to these maximum rating conditions for extended periods may affect device reliability. functional operation of the device at these, or any other conditions above the parameters indicated in the operation listings of this specification, is not implied. absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on v dd with respect to v ss ......................................................................................................... -0.3v to +4.5v voltage on any combined analog and digital pin, with respect to v ss ........................................... -0.3v to (v dd + 0.3v) voltage on any digital only pin with respect to v ss ....................................................................... -0.3v to (v dd + 0.3v) voltage on mclr /v pp pin with respect to v ss ......................................................................................... -0.3v to +9.0v maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ( 1 ) ...........................................................................................................................250 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by all ports .............................................................................................. .........................200 ma maximum current sourced by all ports ( 1 ) ...............................................................................................................200 ma note 1: maximum allowable current is a function of device maximum power dissipation (see tab l e 2 6- 1 ). ?notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic24f16kl402 family ds31037b-page 200 ? 2011 microchip technology inc. 26.1 dc characteristics figure 26-1: pic24f16kl402 family voltage-frequency graph (industrial) table 26-1: thermal operating conditions rating symbol min typ max unit operating junction temperature range t j -40 ? +125 c operating ambient temperature range t a -40 ? +85 c power dissipation: internal chip power dissipation: p int = v dd x (i dd ? ? i oh ) p d p int + p i / o w i/o pin power dissipation: p i / o = ? ({v dd ? v oh } x i oh ) + ? (v ol x i ol ) maximum allowed power dissipation p dmax (t j ? t a )/ ? ja w frequency voltage (v dd ) 1.80v 32 mhz 3.60v 3.00v 3.60v 8 mhz 3.00v note: for frequencies between 8 mhz and 32 mhz, f max = 20 mhz * (v dd ? 1.8) + 8 mhz. table 26-2: thermal packaging characteristics characteristic symbol typ max unit notes package thermal resistance, 20-pin spdip ? ja 62.4 ? c/w 1 package thermal resistance, 28-pin spdip ? ja 60 ? c/w 1 package thermal resistance, 20-pin ssop ? ja 108 ? c/w 1 package thermal resistance, 28-pin ssop ? ja 71 ? c/w 1 package thermal resistance, 20-pin soic ? ja 75 ? c/w 1 package thermal resistance, 28-pin soic ? ja 80.2 ? c/w 1 package thermal resistance, 20-pin qfn ? ja 43 ? c/w 1 package thermal resistance, 28-pin qfn ? ja 32 ? c/w 1 package thermal resistance, 14-pin spdip ? ja 62.4 ?c/w 1 package thermal resistance, 14-pin tssop ? ja 108 ? c/w 1 note 1: junction to ambient thermal resistance, theta- ja ( ? ja ) numbers are achieved by package simulations.
? 2011 microchip technology inc. ds31037b-page 201 pic24f16kl402 family table 26-3: dc characteristics: temperature and voltage specifications dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial para m no. symbol characteristic min typ ( 1 ) max units conditions dc10 v dd supply voltage 1.8 ? 3.6 v dc12 v dr ram data retention voltage ( 2 ) 1.5 ? ? v dc16 v por v dd start voltage to ensure internal power-on reset signal v ss ?0.7v dc17 sv dd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms 0-3.3v in 0.1s 0-2.5v in 60 ms v bg band gap voltage reference 1.14 1.2 1.26 v note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: this is the limit to which v dd can be lowered without losing ram data.
pic24f16kl402 family ds31037b-page 202 ? 2011 microchip technology inc. table 26-4: high/low?voltage detect characteristics table 26-5: bor trip points standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial param no. symbol characteristic min typ max units conditions dc18 v hlvd hlvd voltage on v dd transition hlvdl<3:0> = 0000 ?1.851.94v hlvdl<3:0> = 0001 1.81 1.90 2.00 v hlvdl<3:0> = 0010 1.85 1.95 2.05 v hlvdl<3:0> = 0011 1.90 2.00 2.10 v hlvdl<3:0> = 0100 1.95 2.05 2.15 v hlvdl<3:0> = 0101 2.06 2.17 2.28 v hlvdl<3:0> = 0110 2.12 2.23 2.34 v hlvdl<3:0> = 0111 2.24 2.36 2.48 v hlvdl<3:0> = 1000 2.31 2.43 2.55 v hlvdl<3:0> = 1001 2.47 2.60 2.73 v hlvdl<3:0> = 1010 2.64 2.78 2.92 v hlvdl<3:0> = 1011 2.74 2.88 3.02 v hlvdl<3:0> = 1100 2.85 3.00 3.15 v hlvdl<3:0> = 1101 2.96 3.12 3.28 v hlvdl<3:0> = 1110 3.22 3.39 3.56 v standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. symbol characteristic min typ max units conditions dc19 bor voltage on v dd transition borv = 00 1.85 2.0 2.15 v note 1 borv = 01 2.90 3.0 3.38 v borv = 10 2.53 2.7 3.07 v borv = 11 1.75 1.85 2.05 v note 1: lpbor re-arms the por circuit but does not cause a bor.
? 2011 microchip technology inc. ds31037b-page 203 pic24f16kl402 family table 26-6: dc characteristics: operating current (i dd ) * dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial parameter no. typical ( 1 ) max units conditions i dd current dc20 0.154 0.350 ma 1.8v 0.5 mips, f osc = 1 mhz 0.301 0.630 ma 3.3v dc22 0.300 ? ma 1.8v 1 mips, f osc = 2 mhz 0.585 ? ma 3.3v dc24 7.76 12.0 ma 3.3v 16 mips, f osc = 32 mhz dc26 1.44 ? ma 1.8v frc (4 mips), f osc = 8 mhz 2.71 ? ma 3.3v dc30 4.00 28.0 a 1.8v lprc (15.5 kips), f osc = 31 khz 9.00 55.0 a 3.3v note 1: data in the typical column is at 3.3v, 25c, unless otherwise stated. *i dd is measured with all peripherals disabled. all i/os are configured as outputs and set low; pmdx bits are set to ? 1 ? and wdt, etc., are all disabled. table 26-7: dc characteristics: idle current (i idle ) * dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial parameter no. typical ( 1 ) max units conditions idle current (i idle ) dc40 0.035 0.080 ma 1.8v 0.5 mips, f osc = 1 mhz 0.077 0.150 3.3v dc42 0.076 ? ma 1.8v 1 mips, f osc = 2 mhz 0.146 ? 3.3v dc44 2.52 3.20 ma 3.3v 16 mips, f osc = 32 mhz dc46 0.45 ? ma 1.8v frc (4 mips), f osc = 8 mhz 0.76 ? ma 3.3v dc50 0.87 18.0 a 1.8v lprc (15.5 kips), f osc = 31 khz 1.55 40.0 a 3.3v note 1: data in the typical column is at 3.3v, 25c, unless otherwise stated. *i idle is measured with all i/os configured as outputs and set low; pmdx bits are set to ? 1 ? and wdt, etc., are all disabled.
pic24f16kl402 family ds31037b-page 204 ? 2011 microchip technology inc. table 26-8: dc characteristics: power-down current (i pd ) dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial parameter no. typical ( 1 ) max units conditions power-down current (i pd ) dc60 0.01 0.20 a -40c 1.8v sleep mode ( 2 ) 0.03 0.20 a +25c 0.06 0.87 a +60c 0.20 1.35 a +85c 0.01 0.54 a -40c 3.3v 0.03 0.54 a +25c 0.08 1.68 a +60c 0.25 2.45 a +85c note 1: data in the typical column is at 3.3v, 25c unless otherwise stated. 2: base i pd is measured with all peripherals and clocks disabled. all i/os are configured as outputs and set low; pmdx bits are set to ? 1 ? and wdt, etc., are all disabled table 26-9: dc characteristics: power-down current (i pd ) dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial parameter no. typical ( 1 ) max units conditions module differential current ( ? i pd ) dc71 0.21 0.65 a 1.8v watchdog timer current ? wdt ( 2 , 3 ) 0.45 0.95 a 3.3v dc72 0.69 1.50 a 1.8v 32 khz crystal with timer1: ? sosc (soscsel = 0 ) ( 2 ) 1.00 1.50 a 3.3v dc75 5.24 ? a 1.8v ? hlvd ( 2 , 3 ) 5.16 11.00 a 3.3v dc76 4.15 9.00 a 3.3v ? bor ( 2 , 3 ) dc78 0.03 0.20 a 1.8v ? lpbor ( 2 ) 0.03 0.20 a 3.3v note 1: data in the typical column is at 3.3v, 25c unless otherwise stated. 2: the ? current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 3: this current applies to sleep only.
? 2011 microchip technology inc. ds31037b-page 205 pic24f16kl402 family table 26-10: dc characteristics: i/o pin input specifications dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions v il input low voltage ( 4 ) ???? di10 i/o pins v ss ? 0.2 v dd v di15 mclr v ss ? 0.2 v dd v di16 osci (xt mode) v ss ? 0.2 v dd v di17 osci (hs mode) v ss ? 0.2 v dd v di18 i/o pins with i 2 c? buffer v ss ? 0.3 v dd v smbus disabled di19 i/o pins with smbus buffer v ss ? 0.8 v smbus enabled v ih input high voltage ( 4 , 5 ) ???? di20 i/o pins: with analog functions digital only 0.8 v dd 0.8 v dd ? ? v dd v dd v v di25 mclr 0.8 v dd ?v dd v di26 osci (xt mode) 0.7 v dd ?v dd v di27 osci (hs mode) 0.7 v dd ?v dd v di28 i/o pins with i 2 c buffer: with analog functions digital only 0.7 v dd 0.7 v dd ? ? v dd v dd v v di29 i/o pins with smbus 2.1 ? v dd v2.5v ? v pin ? v dd di30 i cnpu cnx pull-up current 50 250 500 ? av dd = 3.3v, v pin = v ss di31 i pu maximum load current for digital high detection w/internal pull-up ??30 ? av dd = 2.0v ? ? 1000 ? av dd = 3.3v i il input leakage current ( 2 , 3 ) di50 i/o ports ? 0.050 0.100 ? av ss ? v pin ? v dd , pin at high-impedance di51 v ref +, v ref -, an0, an1 ? 0.300 0.500 ? av ss ? v pin ? v dd , pin at high-impedance note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: refer to ta b l e 1 - 4 and tab l e 1 - 5 for i/o pin buffer types. 5: v ih requirements are met when the internal pull-ups are enabled.
pic24f16kl402 family ds31037b-page 206 ? 2011 microchip technology inc. table 26-11: dc characteristics: i/o pin output specifications dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions v ol output low voltage ?? do10 all i/o pins ? ? 0.4 v i ol = 4.0 ma v dd = 3.6v ??0.4vi ol = 3.5 ma v dd = 2.0v do16 osc2/clko ? ? 0.4 v i ol = 1.2 ma v dd = 3.6v ??0.4vi ol = 0.4 ma v dd = 2.0v v oh output high voltage do20 all i/o pins 3 ? ? v i oh = -3.0 ma v dd = 3.6v 1.6 ? ? v i oh = -1.0 ma v dd = 2.0v do26 osc2/clko 3 ? ? v i oh = -1.0 ma v dd = 3.6v 1.6 ? ? v i oh = -0.5 ma v dd = 2.0v note 1: data in ?typ? column is at 25c unless otherwise stated. table 26-12: dc characteristics: program memory dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions program flash memory d130 e p cell endurance 10,000 ( 2 ) ??e/w d131 v pr v dd for read v min ?3.6vv min = minimum operating voltage d133a t iw self-timed write cycle time ?2?ms d134 t retd characteristic retention 40 ? ? year provided no other specifications are violated d135 i ddp supply current during programming ?10?ma note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. 2: self-write and block erase.
? 2011 microchip technology inc. ds31037b-page 207 pic24f16kl402 family table 26-14: dc specif ications: comparator table 26-15: dc specifications: comparator voltage reference s table 26-13: dc characteristics: data eeprom memory dc characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions data eeprom memory d140 e pd cell endurance 100,000 ? ? e/w d141 v prd v dd for read v min ?3.6vv min = minimum operating voltage d143a t iwd self-timed write cycle time ?4 ?ms d143b t ref number of total write/erase cycles before refresh ?10m ?e/w d144 t retdd characteristic retention 40 ? ? year provided no other specifications are violated d145 i ddpd supply current during programming ?7 ?ma note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. operating conditions: 2.0v < v dd < 3.6v, -40c < t a < +85c (unless otherwise stated) param no. symbol characteristic min typ max units comments d300 v ioff input offset voltage ? 20 40 mv d301 v icm input common mode voltage 0 ? v dd v d302 cmrr common mode rejection ratio 55 ? ? db operating conditions: 2.0v < v dd < 3.6v, -40c < t a < +85c (unless otherwise stated) param no. symbol characteristic min typ max units comments vrd310 cv res resolution ? ? v dd /32 lsb vrd311 cvr aa absolute accuracy ? ? av dd ? 1.5 lsb vrd312 cvr ur unit resistor value (r) ? 2k ? ?
pic24f16kl402 family ds31037b-page 208 ? 2011 microchip technology inc. 26.2 ac characteristics and timing parameters the information contained in this section defines the pic24f16kl402 family ac characteristics and timing parameters. table 26-16: temperature and vo ltage specifications ? ac figure 26-2: load conditions for device timing specifications table 26-17: capacitiv e loading requirements on output pins ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature-40c ? t a ? +85c for industrial operating voltage v dd range as described in section 26.1 ?dc characteristics? . param no. symbol characteristic min typ ( 1 ) max units conditions do50 c osc 2 osco/clko pin ? ? 15 pf in xt and hs modes when external clock is used to drive osci do56 c io all i/o pins and osco ? ? 50 pf ec mode do58 c b sclx, sdax ? ? 400 pf in i 2 c? mode note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osco 15 pf for osco output load condition 1 ? for all pins except osco load condition 2 ? for osco
? 2011 microchip technology inc. ds31037b-page 209 pic24f16kl402 family figure 26-3: external clock timing osci clko q4 q1 q2 q3 q4 q1 os20 os25 os30 os30 os40 os41 os31 os31 q1 q2 q3 q4 q2 q3 table 26-18: external clo ck timing requirements ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions os10 f osc external clki frequency (external clocks allowed only in ec mode) dc 4 ? ? 32 8 mhz mhz ec ecpll oscillator frequency 0.2 4 4 31 ? ? ? ? 4 25 8 33 mhz mhz mhz khz xt hs xtpll sosc os20 t osc t osc = 1/f osc ? ? ? ? see parameter # os10 for f osc value os25 t cy instruction cycle time ( 2 ) 62.5 ? dc ns os30 tosl, to s h external clock in (osci) high or low time 0.45 x t osc ??nsec os31 tosr, to s f external clock in (osci) rise or fall time ??20nsec os40 tckr clko rise time ( 3 ) ?610ns os41 tckf clko fall time ( 3 ) ?610ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: instruction cycle period (t cy ) equals two times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osci/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. 3: measurements are taken in ec mode. the clko signal is measured on the osco pin. clko is low for the q1-q2 period (1/2 t cy ) and high for the q3-q4 period (1/2 t cy ).
pic24f16kl402 family ds31037b-page 210 ? 2011 microchip technology inc. table 26-19: pll clock ti ming specifications ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic ( 1 ) min typ ( 2 ) max units conditions os50 f plli pll input frequency range 4 ? 8 mhz ecpll, hspll modes, -40c ? t a ? +85c os51 f sys pll output frequency range 16 ? 32 mhz -40c ? t a ? +85c os52 t lock pll start-up time (lock time) ?1 2ms os53 d clk clko stability (jitter) -2 1 2 % measured over 100 ms period note 1: these parameters are characterized but not tested in manufacturing. 2: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. table 26-20: internal rc oscillator accuracy ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. characteristic min typ max units conditions f20 frc @ 8 mhz ( 1 ) -2 ? +2 % +25c 3.0v ? v dd ? 3.6v -5 ? +5 % -40c ? t a ?? +85c 1.8v ? v dd ? 3.6v f21 lprc @ 31 khz ( 2 ) -15 ? +15 % -40c ? t a ?? +85c 1.8v ? v dd ? 3.6v note 1: the frequency is calibrated at 25c and 3.3v. the osctun bits can be used to compensate for temperature drift. 2: the change of lprc frequency as v dd changes. table 26-21: internal rc os cillator specifications ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ max units conditions t frc frc start-up time ? 5 ? ? s t lprc lprc start-up time ? 70 ? ? s
? 2011 microchip technology inc. ds31037b-page 211 pic24f16kl402 family figure 26-4: clko and i/o ti ming characteristics note: refer to figure 26-2 for load conditions. i/o pin (input) i/o pin (output) di35 old value new value di40 do31 do32 table 26-22: clko and i/ o timing requirements ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions do31 t io r port output rise time ? 10 25 ns do32 t io f port output fall time ? 10 25 ns di35 t inp intx pin high or low time (output) 20 ? ? ns di40 t rbp cnx high or low time (input) 2??t cy note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated.
pic24f16kl402 family ds31037b-page 212 ? 2011 microchip technology inc. table 26-23: reset, watchdog timer, oscill ator start-up timer, power-up timer, and brown-out reset timing requirements table 26-24: comp arator timings table 26-25: comparator voltage re ference settling time specifications ac characteristics standard operating conditions: 1.8v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. symbol characteristic min. typ ( 1 ) max. units conditions sy10 tmcl mclr pulse width (low) 2 ? ? ? s sy11 t pwrt power-up timer period 50 64 90 ms sy12 t por power-on reset delay 1 5 10 ? s sy13 t ioz i/o high-impedance from mclr low or watchdog timer reset ? ? 100 ns sy20 t wdt watchdog timer time-out period 0.85 1.0 1.15 ms 1.32 prescaler 3.4 4.0 4.6 ms 1:128 prescaler sy25 t bor brown-out reset pulse width 1? ? ? s sy45 t rst internal state reset time ? 5 ? ? s sy55 t lock pll start-up time ? 100 ? ? s sy65 t ost oscillator start-up time ? 1024 ? t osc sy71 t pm program memory wake-up time ?1 ? ? s sleep wake-up with pmslp = 0 note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. param no. symbol characteristic min typ max units comments 300 t resp response time * ( 1 ) ? 150 400 ns 301 t mc 2 ov comparator mode change to output valid * ?? 10 ? s * parameters are characterized but not tested. note 1: response time is measured with one comparator input at (v dd ? 1.5)/2, while the other input transitions from v ss to v dd . param no. symbol characteristic min typ max units comments vr310 t set settling time ( 1 ) ??10 ? s note 1: settling time is measured while cvrss = 1 and cvr<3:0> bits transition from ? 0000 ? to ? 1111 ?.
? 2011 microchip technology inc. ds31037b-page 213 pic24f16kl402 family figure 26-5: capture/compare/pwm timing s (eccp1, eccp2 modules) table 26-26: capture/compare/pwm requirements (eccp1, eccp2 modules) param no. symbol characteristic min max units conditions 50 t cc l ccpx input low time no prescaler 0.5 t cy + 20 ? ns with prescaler 20 ? ns 51 t cc h ccpx input high time no prescaler 0.5 t cy + 20 ? ns with prescaler 20 ? ns 52 t cc p ccpx input period greater of: 40, or 2 t cy + 40 n ? ns n = prescale value (1, 4 or 16) 53 t cc r ccpx output fall time ? 25 ns 54 t cc f ccpx output fall time ? 25 ns note: refer to figure 26-2 for load conditions. ccpx (capture mode) 50 51 52 ccpx 53 54 (compare or pwm mode)
pic24f16kl402 family ds31037b-page 214 ? 2011 microchip technology inc. figure 26-6: example spi ma ster mode timing (cke = 0 ) table 26-27: example spi mode requirements (master mode, cke = 0 ) param no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns f sck sckx frequency ? 10 mhz sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix 73 74 75, 76 78 79 79 78 msb lsb bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 note: refer to figure 26-2 for load conditions. msb in
? 2011 microchip technology inc. ds31037b-page 215 pic24f16kl402 family figure 26-7: example spi ma ster mode timing (cke = 1 ) table 26-28: example spi mode requirements (master mode, cke = 1 ) param. no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 35 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 81 t do v2 sc h, t do v2 sc l sdox data output setup to sckx edge t cy ?ns f sck sckx frequency ? 10 mhz sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix 81 74 75, 76 78 msb 79 73 bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 lsb note: refer to figure 26-2 for load conditions. msb in
pic24f16kl402 family ds31037b-page 216 ? 2011 microchip technology inc. figure 26-8: example spi sl ave mode timing (cke = 0 ) table 26-29: example spi mode requirements (slave mode timing, cke = 0 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx ? to sckx ? or sckx ? input 3 t cy ?ns 70a t ss l2wb ssx to write to sspxbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1 ) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1 ) 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2 ) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx ? to sdox output high-impedance 10 50 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx ? after sckx edge 1.5 t cy + 40 ? ns f sck sckx frequency ? 10 mhz note 1: requires the use of parameter # 73a . 2: only if parameter # 71a and # 72a are used. ssx sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix 70 71 72 73 74 75, 76 77 80 msb lsb bit 6 - - - - - - 1 bit 6 - - - - 1 lsb in 83 note: refer to figure 26-2 for load conditions. msb in
? 2011 microchip technology inc. ds31037b-page 217 pic24f16kl402 family figure 26-9: example spi sl ave mode timing (cke = 1 ) table 26-30: example spi slave mode requirements (cke = 1 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx ? to sckx ? or sckx ? input 3 t cy ?ns 70a t ss l2wb ssx to write to sspxbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1 ) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1 ) 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2 ) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx ? to sdox output high-impedance 10 50 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 82 t ss l2 do v sdox data output valid after ssx ? edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx ? after sckx edge 1.5 t cy + 40 ? ns f sck sckx frequency ? 10 mhz note 1: requires the use of parameter # 73a . 2: only if parameter # 71a and # 72a are used. ssx sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdi 70 71 72 82 sdix 74 75, 76 msb bit 6 - - - - - - 1 lsb 77 bit 6 - - - - 1 lsb in 80 83 73 msb in note: refer to figure 26-2 for load conditions.
pic24f16kl402 family ds31037b-page 218 ? 2011 microchip technology inc. figure 26-10: i 2 c? bus start/stop bits timing table 26-31: i 2 c? bus start/stop bits requirements (slave mode) figure 26-11: i 2 c? bus data timing param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? 91 t hd : sta start condition 100 khz mode 4000 ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? 92 t su : sto stop condition 100 khz mode 4700 ? ns setup time 400 khz mode 600 ? 93 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? note: refer to figure 26-2 for load conditions. 91 92 93 sclx sdax start condition stop condition 90 note: refer to figure 26-2 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
? 2011 microchip technology inc. ds31037b-page 219 pic24f16kl402 family table 26-32: i 2 c? bus data requirements (slave mode) param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? ? s must operate at a minium of 1.5 mhz 400 khz mode 0.6 ? ? s must operate at a minium of 10 mhz mssp module 1.5 t cy ? 101 t low clock low time 100 khz mode 4.7 ? ? s must operate at a minium of 1.5 mhz 400 khz mode 1.3 ? ? s must operate at a minium of 10 mhz mssp module 1.5 t cy ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sdax and sclx fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? ? s only relevant for repeated start condition 400 khz mode 0.6 ? ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2 ) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? ? s 400 khz mode 0.6 ? ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1 ) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s d102 c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provide this internal mini mum delay time to bridge the undefined region (min. 300 ns) of the falling edge of sclx to avoid unintended generation of start or stop conditions. 2: a fast mode i 2 c? bus device can be used in a standard mode i 2 c bus system, but the requirement, t su : dat ? 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the sclx line is released.
pic24f16kl402 family ds31037b-page 220 ? 2011 microchip technology inc. figure 26-12: mssp i 2 c? bus start/stop bits timing waveforms table 26-33: i 2 c? bus start/stop bits requirements (master mode) param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns only relevant for repeated start condition setup time 400 khz mode 2(t osc )(brg + 1) ? 91 t hd : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns after this period, the first clock pulse is generated hold time 400 khz mode 2(t osc )(brg + 1) ? 92 t su : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ? ns setup time 400 khz mode 2(t osc )(brg + 1) 93 t hd : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns hold time 400 khz mode 2(t osc )(brg + 1) ? note: refer to figure 26-2 for load conditions. 91 93 sclx sdax start condition stop condition 90 92
? 2011 microchip technology inc. ds31037b-page 221 pic24f16kl402 family figure 26-13: mssp i 2 c? bus data timing table 26-34: i 2 c? bus data requirements (master mode) note: refer to figure 26-2 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 101 t low clock low time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 103 t f sdax and sclx fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? ? only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? ? 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? ? after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? ? 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 1 ) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 109 t aa output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 110 t buf bus free time 100 khz mode 400 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 1.3 ? ? s d102 c b bus capacitive loading ? 400 pf note 1: a fast mode i 2 c bus device can be used in a standard mode i 2 c bus system, but parameter ? 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, parameter + parameter = 1000 + 250 = 1250 ns (for 100 khz mode), before the sclx line is released.
pic24f16kl402 family ds31037b-page 222 ? 2011 microchip technology inc. table 26-35: a/d mo dule specifications ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial param no. symbol characteristic min. typ max. units conditions device supply ad01 av dd module v dd supply greater of v dd ? 0.3 or 1.8 ? lesser of v dd + 0.3 or 3.6 v ad02 av ss module v ss supply v ss ? 0.3 ? v ss + 0.3 v reference inputs ad05 v refh reference voltage high av ss + 1.7 ? av dd v ad06 v refl reference voltage low av ss ?av dd ? 1.7 v ad07 v ref absolute reference voltage av ss ? 0.3 ? av dd + 0.3 v analog input ad10 v inh -v inl full-scale input span v refl ?v refh v (note 1 ) ad11 v in absolute input voltage av ss ? 0.3 ? av dd + 0.3 v ad12 v inl absolute v inl input voltage av ss ? 0.3 av dd /2 v ad17 r in recommended impedance of analog voltage source ? ? 2.5k ? 10-bit a/d accuracy ad20b n r resolution ? 10 ? bits ad21b inl integral nonlinearity ? 1 2 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad22b dnl differential nonlinearity ? 1 1.5 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad23b g err gain error ? 1 3 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad24b e off offset error ? 1 2 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad25b monotonicity ? ? ? ? (note 2 ) note 1: measurements are taken with external v ref + and v ref - used as the a/d voltage reference. 2: the a/d conversion result never decreases with an increase in the input voltage.
? 2011 microchip technology inc. ds31037b-page 223 pic24f16kl402 family table 26-36: a/d conversion timing requirements ( 1 ) ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial param no. symbol characteristic min. typ max. units conditions clock parameters ad50 t ad a/d clock period 75 ? ? ns t cy = 75 ns, ad1con3 in default state ad51 t rc a/d internal rc oscillator period ? 250 ? ns conversion rate ad55 t conv conversion time ? 12 ? t ad ad56 f cnv throughput rate ? ? 500 ksps av dd ? 2.7v ad57 t samp sample time ? 1 ? t ad ad58 t acq acquisition time 750 ? ? ns (note 2 ) ad59 t swc switching time from convert to sample ?? (note 3 ) ad60 t dis discharge time 0.5 ? ? t ad clock parameters ad61 t pss sample start delay from setting sample bit (samp) 2? 3 t ad note 1: because the sample caps will eventually lose charge, clock rates below 10 khz can affect linearity performance, especially at elevated temperatures. 2: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). 3: on the following cycle of the device clock.
pic24f16kl402 family ds31037b-page 224 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 225 pic24f16kl402 family 27.0 packaging information 27.1 package marking information legend: xx...x product-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note: in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 20-lead pdip (300 mil) example xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn 14-lead pdip (300 mil) example 28-lead spdip (.300?) example PIC24F04KL100 3 e -i/p 1116012 3 e 3 e pic24f08kl201 -i/p 1116012 pic24f16kl302 -i/sp 1116012
pic24f16kl402 family ds31037b-page 226 ? 2011 microchip technology inc. 20-lead ssop (5.30 mm) example 20-lead soic (7.50 mm) example xxxxxxxxxxxx yywwnnn xxxxxxxxxxxx xxxxxxxxxxxx 28-lead oic (.50 mm) examle yywwnnn xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx 3 e 3 e 3 e pic24f08kl 401-i/ss 1116012 pic24f08kl301 -i/so 1116012 pic24f08kl302 -i/so 1116012 14-lead tssop (4.4 mm) example yyww nnn xxxxxxxx 1116 012 24f08kl1
? 2011 microchip technology inc. ds31037b-page 227 pic24f16kl402 family 20-lead qfn (5x5x0.9 mm) example pin 1 pin 1 28-lead qfn (6x6 mm) example xxxxxxxx xxxxxxxx yywwnnn pin 1 pin 1 3 e pic24f08 kl301 -i/mq 1116012 3 e pic24f08kl 301-i/ml 1116012 28-lead qfn (5x5x0.9 mm) example pin 1 pin 1 3 e pic24f08 kl302 -i/ml 1116012 28-lead ssop (5.30 mm) example 3 e pic24f08kl 402-i/ss 1116012
pic24f16kl402 family ds31037b-page 228 ? 2011 microchip technology inc. 27.2 package details the following sections give the technical details of the packages. n e1 d note 1 12 3 e c eb a2 l a a1 b1 be
? 2011 microchip technology inc. ds31037b-page 229 pic24f16kl402 family n e1 note 1 d 123 a a1 a2 l e b1 b e c eb
pic24f16kl402 family ds31037b-page 230 ? 2011 microchip technology inc. note 1 n 12 d e1 eb c e l a2 e b b1 a1 a 3
? 2011 microchip technology inc. ds31037b-page 231 pic24f16kl402 family d e e1 e b 123 note 1 a a1 a2 h h c l1 l n
pic24f16kl402 family ds31037b-page 232 ? 2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2011 microchip technology inc. ds31037b-page 233 pic24f16kl402 family c h h l l1 a2 a1 a note 1 12 3 b e e e1 d n
pic24f16kl402 family ds31037b-page 234 ? 2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2011 microchip technology inc. ds31037b-page 235 pic24f16kl402 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16kl402 family ds31037b-page 236 ? 2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2011 microchip technology inc. ds31037b-page 237 pic24f16kl402 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16kl402 family ds31037b-page 238 ? 2011 microchip technology inc. l l1 a2 c e b a1 a 12 note 1 e1 e d n
? 2011 microchip technology inc. ds31037b-page 239 pic24f16kl402 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16kl402 family ds31037b-page 240 ? 2011 microchip technology inc. l l1 c a2 a1 a e e1 d n 1 2 note 1 b e
? 2011 microchip technology inc. ds31037b-page 241 pic24f16kl402 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16kl402 family ds31037b-page 242 ? 2011 microchip technology inc. 20-lead plastic quad flat, no lead package (mq) ? 5x5x0.9 mm body [qfn] note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging microchip technology drawing c04-120a
? 2011 microchip technology inc. ds31037b-page 243 pic24f16kl402 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16kl402 family ds31037b-page 244 ? 2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2011 microchip technology inc. ds31037b-page 245 pic24f16kl402 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16kl402 family ds31037b-page 246 ? 2011 microchip technology inc. 28-lead plastic quad flat, no lead package (mq) C 5x5 mm body [qfn] land pattern with 0.55 mm contact length note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging microchip technology drawing c04-2140a
? 2011 microchip technology inc. ds31037b-page 247 pic24f16kl402 family d exposed d2 e b k e2 e l n note 1 1 2 2 1 n a a1 a3 top view bottom view pad
pic24f16kl402 family ds31037b-page 248 ? 2011 microchip technology inc.
? 2011 microchip technology inc. ds31037b-page 249 pic24f16kl402 family appendix a: revision history revision a (september 2011) original data sheet for the pic24f16kl402 family of devices. revision b (november 2011) updates dc specifications in tables 26-6 through 26-9 (all typical and maximum values). updates ac specifications in tables 26-7 through 26-30 (spi timing requirements) with the addition of the f sck specification. other minor typographic corrections throughout. appendix b: migrating from pic18/pic24 to pic24f16kl402 the pic24f16kl402 family combines traditional pic18 peripherals with a faster pic24 core to provide a low-cost, high-performance microcontroller with low-power consumption. code written for pic18 devices can be migrated to the pic24f16kl402 by using a c compiler that generates pic24 machine level instructions. assembly language code will need to be rewritten using pic24 instructions. the pic24 instruction set shares similarities to the pic18 instruction set, which should ease porting of assembly code. application code will require changes to support certain pic24 peripherals. code written for pic24 devices can be migrated to the pic24f16kl402 without many code changes. certain peripherals, however, will require application changes to support modules that were traditionally available only on pic18 devices. refer to tab l e b - 1 for a list of peripheral modules on the pic24f16kl402 and where they originated from. table b-1: table b-1: pic24f16kl402 peripheral module originating architecture peripheral module pic18 pic24 eccp/ccp x ? mssp (i 2 c?/spi) x ? timer2/4 (8-bit) x ? timer3 (16-bit) x ? timer1 (16-bit) ? x 10-bit a/d converter ? x comparator ? x comparator voltage reference ?x uart ? x hlvd ? x
pic24f16kl402 family ds31037b-page 250 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 251 pic24f16kl402 family index a a/d 10-bit high-speed a/d converter............................. 159 conversion timing requirements............................. 225 module specifications ............................................... 224 a/d converter analog input model ................................................... 166 transfer function...................................................... 167 ac characteristics capacitive loading requirements on output pins ....................................................... 210 internal rc accuracy ................................................ 212 internal rc oscillator specifications......................... 212 load conditions and requirements.......................... 210 temperature and voltage specifications .................. 210 assembler mpasm assembler................................................... 190 b block diagrams 10-bit high-speed a/d converter............................. 160 16-bit timer1 ............................................................ 117 accessing program memory with table instructions ............................................... 47 call stack frame...................................................... 45 capture mode operation .......................................... 128 comparator module .................................................. 169 comparator voltage reference ................................ 173 compare mode operation ........................................ 128 cpu programmer?s model .......................................... 29 data access from program space address generation ............................................ 46 data eeprom addressing with tblpag and nvm registers............................................. 57 enhanced pwm mode .............................................. 129 high/low-voltage detect (hlvd) ............................. 175 individual comparator configurations....................... 170 mssp (i 2 c master mode) ......................................... 139 mssp (i 2 c mode) ..................................................... 139 mssp (spi mode)..................................................... 138 pic24f cpu core ...................................................... 28 pic24f16kl402 family (general).............................. 15 psv operation ............................................................ 48 pwm operation (simplified) ..................................... 128 reset system.............................................................. 61 serial resistor........................................................... 109 shared i/o port structure ......................................... 113 simplified uart........................................................ 151 spi master/slave connection ................................... 138 system clock .............................................................. 97 table register addressing.......................................... 49 timer2....................................................................... 119 timer3....................................................................... 121 timer4....................................................................... 125 watchdog timer (wdt) ............................................ 186 c c compilers mplab c18 .............................................................. 190 capture/compare/pwm (ccp)......................................... 127 ccp/eccp ccp i/o pins............................................................. 127 timer selection ......................................................... 127 code examples data eeprom bulk erase ......................................... 59 data eeprom unlock sequence .............................. 55 erasing a program memory row, ?c? language code............................................. 53 erasing a program memory row, assembly language code ................................. 52 i/o port write/read .................................................. 116 initiating a programming sequence, ?c? language code............................................. 54 initiating a programming sequence, assembly language code ................................. 54 loading the write buffers, ?c? language code .......... 54 loading the write buffers, assembly language code .................................................. 53 pwrsav instruction syntax .................................... 107 reading the data eeprom using the tblrd command .............................................. 60 sequence for clock switching.................................. 104 single-word erase ..................................................... 58 single-word write to data eeprom ......................... 59 ultra low-power wake-up initialization.................... 109 code protection ................................................................ 187 comparator....................................................................... 169 comparator voltage reference ........................................ 173 configuring ............................................................... 173 configuration bits ............................................................. 177 core features..................................................................... 11 cpu alu............................................................................. 31 control registers........................................................ 30 core registers............................................................ 28 programmer?s model .................................................. 27 customer change notification service............................. 257 customer notification service .......................................... 257 customer support............................................................. 257 d data eeprom memory...................................................... 55 erasing ....................................................................... 58 operations .................................................................. 57 programming bulk erase .......................................................... 59 reading data eeprom ..................................... 60 single-word write .............................................. 59 programming control registers nvmadr(u) ....................................................... 57 nvmcon............................................................ 55 nvmkey ............................................................ 55 data memory address space ........................................................... 35 memory map............................................................... 35 near data space ........................................................ 36 organization ............................................................... 36 sfr space ................................................................. 36 software stack ........................................................... 45 space width ............................................................... 35
pic24f16kl402 family ds31037b-page 252 ? 2011 microchip technology inc. dc characteristics bor trip points ........................................................ 204 comparator ............................................................... 209 comparator voltage reference ................................ 209 data eeprom memory............................................ 209 high/low-voltage detect .......................................... 204 i/o pin input specifications ....................................... 207 i/o pin output specifications .................................... 208 idle current (i idle ) .................................................... 205 operating current (i dd )............................................. 205 power-down current (i pd ) ........................................ 206 program memory ...................................................... 208 temperature and voltage specifications .................. 203 development support ....................................................... 189 device features for pic24f16kl20x/10x family (summary)....................................................... 14 device features for pic24f16kl40x/30x family (summary)....................................................... 13 e electrical characteristics absolute maximum ratings ...................................... 201 thermal operating conditions .................................. 202 thermal packaging characteristics .......................... 202 v/f graphs................................................................ 202 enhanced ccp ................................................................. 127 equations a/d conversion clock period ................................... 166 uart baud rate with brgh = 0 ............................. 152 uart baud rate with brgh = 1 ............................. 152 errata .................................................................................... 9 examples baud rate error calculation (brgh = 0) ................. 152 f flash program memory control registers ........................................................ 50 enhanced icsp operation.......................................... 50 programming algorithm .............................................. 52 programming operations............................................ 50 rtsp operation.......................................................... 50 table instructions........................................................ 49 g getting started guidelines for 16-bit mcus ....................... 23 h high/low-voltage detect (hlvd) ..................................... 175 i i/o ports analog port configuration ......................................... 114 analog selection registers ....................................... 114 input change notification.......................................... 116 open-drain configuration ......................................... 114 parallel (pio) ............................................................ 113 in-circuit debugger ........................................................... 187 in-circuit serial programming (icsp) ............................... 187 instruction set opcode symbols....................................................... 194 overview ................................................................... 195 summary................................................................... 193 inter-integrated circuit. see i 2 c. internet address................................................................ 257 interrupt sources tmr3 overflow......................................................... 121 tmr4 to pr4 match (pwm) ..................................... 125 interrupts alternate interrupt vector table (aivt) ...................... 67 control and status registers...................................... 70 implemented vectors.................................................. 69 interrupt vector table (ivt) ........................................ 67 reset sequence ......................................................... 67 setup procedures ....................................................... 96 trap vectors ............................................................... 69 vector table ............................................................... 68 m master synchronous serial port (mssp) ......................... 137 microchip internet web site.............................................. 257 mplab asm30 assembler, linker, librarian ................... 190 mplab integrated development environment software .............................................. 189 mplab pm3 device programmer .................................... 192 mplab real ice in-circuit emulator system ................ 191 mplink object linker/mplib object librarian ................ 190 n near data space ................................................................ 36 o oscillator configuration clock switching ........................................................ 103 sequence ......................................................... 103 configuration bit values for clock selection .............. 98 cpu clocking scheme ............................................... 98 initial configuration on por ....................................... 98 reference clock output ........................................... 104 oscillator, timer3.............................................................. 121 p packaging details....................................................................... 230 marking ..................................................................... 227 pinout descriptions for pic24f16kl20x/10x family......... 20 pinout descriptions for pic24f16kl40x/30x family......... 16 power-saving ................................................................... 111 power-saving features .................................................... 107 clock frequency, clock switching ........................... 107 coincident interrupts................................................. 108 instruction-based modes.......................................... 107 idle .................................................................... 108 sleep ................................................................ 108 selective peripheral control ..................................... 111 ultra low-power wake-up (ulpwu) ....................... 109 product identification system ........................................... 259 program and data memory access using table instructions................................. 47 program space visibility............................................. 48 program and data memory spaces addressing.................................................................. 45 interfacing ................................................................... 45 program memory address space ........................................................... 33 device configuration words ....................................... 34 hard memory vectors................................................. 34 memory map............................................................... 33 organization ............................................................... 34
? 2011 microchip technology inc. ds31037b-page 253 pic24f16kl402 family program verification ......................................................... 187 pwm (ccp module) tmr4 to pr4 match ................................................. 125 r reader response ............................................................. 258 register maps a/d converter ............................................................. 43 analog select.............................................................. 43 ccp/eccp ................................................................. 40 comparator ................................................................. 43 cpu core.................................................................... 37 icn.............................................................................. 38 interrupt controller ...................................................... 39 mssp.......................................................................... 41 nvm ............................................................................ 44 pad configuration ....................................................... 42 pmd ............................................................................ 44 porta........................................................................ 42 portb........................................................................ 42 system, clock control ................................................ 44 timer........................................................................... 40 uart .......................................................................... 41 ultra low-power wake-up .......................................... 44 registers ad1chs (a/d input select) ...................................... 164 ad1con1 (a/d control 1) ........................................ 161 ad1con2 (a/d control 2) ........................................ 162 ad1con3 (a/d control 3) ........................................ 163 ad1cssl (a/d input scan select, low) .................. 165 ancfg (analog input configuration) ....................... 165 ansa (analog selection, porta) ........................... 115 ansb (analog selection, portb) ........................... 115 ccp1con enhanced (eccp1) .......................................... 131 ccptmrs0 (ccp timer select) .............................. 135 ccpxcon standard ccp................................................... 130 clkdiv (clock divider) ............................................ 101 cmstat (comparator status).................................. 172 cmxcon (comparator x control)............................. 171 corcon (cpu control) ............................................ 31 corcon (cpu core control).................................... 72 cvrcon (comparator voltage reference control) ........................................... 174 devid (device id) .................................................... 184 devrev (device revision) ...................................... 185 eccp1as (eccp1 auto-shutdown control)............ 132 eccp1del (eccp1 enhanced pwm control) ........ 133 fbs (boot segment configuration) .......................... 178 fgs (general segment configuration)..................... 178 ficd (in-circuit debugger configuration)................. 183 fosc (oscillator configuration) ............................... 180 foscsel (oscillator selection configuration)......... 179 fpor (reset configuration)..................................... 182 fwdt (watchdog timer configuration) ................... 181 hlvdcon (high/low-voltage detect control)......... 176 iec0 (interrupt enable control 0) ............................... 79 iec1 (interrupt enable control 1) ............................... 80 iec2 (interrupt enable control 2) ............................... 81 iec3 (interrupt enable control 3) ............................... 81 iec4 (interrupt enable control 4) ............................... 82 iec5 (interrupt enable control 5) ............................... 82 ifs0 (interrupt flag status 0) ..................................... 75 ifs1 (interrupt flag status 1) ..................................... 76 ifs2 (interrupt flag status 2) ..................................... 77 ifs3 (interrupt flag status 3) ..................................... 77 ifs4 (interrupt flag status 4) ..................................... 78 ifs5 (interrupt flag status 5) ..................................... 78 intcon 2 (interrupt control 2) .................................. 74 intcon1 (interrupt control 1) ................................... 73 inttreg (interrupt control and status) .................... 95 ipc0 (interrupt priority control 0) ............................... 83 ipc1 (interrupt priority control 1) ............................... 84 ipc12 (interrupt priority control 12) ........................... 92 ipc16 (interrupt priority control 16) ........................... 93 ipc18 (interrupt priority control 18) ........................... 94 ipc2 (interrupt priority control 2) ............................... 85 ipc20 (interrupt priority control 20) ........................... 94 ipc3 (interrupt priority control 3) ............................... 86 ipc4 (interrupt priority control 4) ............................... 87 ipc5 (interrupt priority control 5) ............................... 88 ipc6 (interrupt priority control 6) ............................... 89 ipc7 (interrupt priority control 7) ............................... 90 ipc9 (interrupt priority control 9) ............................... 91 nvmcon (flash memory control)............................. 51 nvmcon (nonvolatile memory control).................... 56 osccon (oscillator control)..................................... 99 osctun (frc oscillator tune) .............................. 102 padcfg1 (pad configuration control).................... 149 pstr1con (eccp pulse steering) ........................ 134 rcon (reset control)................................................ 62 refocon (reference oscillator control) ............... 105 sr (alu status) ............................................... 30, 71 sspxadd (msspx slave address/baud rate generator)................................................ 148 sspxcon1 (msspx control 1) i 2 c mode .......................................................... 144 spi mode.......................................................... 143 sspxcon2 (msspx control 2)................................ 145 sspxcon3 (msspx control 3) i 2 c mode .......................................................... 147 spi mode.......................................................... 146 sspxmsk (i 2 c slave address mask) ...................... 148 sspxstat (msspx status) i 2 c mode .......................................................... 141 spi mode.......................................................... 140 t1con (timer1 control) .......................................... 118 t2con (timer2 control) .......................................... 120 t3gcon (timer3 gate control)............................... 123 t4con (timer4 control) .......................................... 126 ulpwcon (ulpwu control) .................................. 110 uxmode (uartx mode) ......................................... 154 uxsta (uartx status and control) ........................ 156 resets brown-out reset (bor).............................................. 65 clock source selection .............................................. 63 delay times................................................................ 64 device times.............................................................. 64 rcon flag operation ................................................ 63 sfr states ................................................................. 65 revision history................................................................ 251 s serial peripheral interface. see spi mode. sfr space ......................................................................... 36 software simulator (mplab sim) .................................... 191 software stack ................................................................... 45
pic24f16kl402 family ds31037b-page 254 ? 2011 microchip technology inc. t timer1 ............................................................................... 117 timer2 ............................................................................... 119 timer3 ............................................................................... 121 oscillator ................................................................... 121 overflow interrupt ..................................................... 121 timer4 ............................................................................... 125 pr4 register............................................................. 125 tmr4 register.......................................................... 125 tmr4 to pr4 match interrupt ................................... 125 timing diagrams capture/compare/pwm (eccp1, eccp2) .............. 215 clko and i/o timing................................................ 213 example spi master mode (cke = 0) ...................... 216 example spi master mode (cke = 1) ...................... 217 example spi slave mode (cke = 0) ........................ 218 example spi slave mode (cke = 1) ........................ 219 external clock........................................................... 211 i 2 c bus data ............................................................. 220 i 2 c bus start/stop bits.............................................. 220 mssp i 2 c bus data .................................................. 222 mssp i 2 c bus start/stop bits .................................. 222 timing requirements capture/compare/pwm (eccp1, eccp2) .............. 215 clko and i/o ........................................................... 213 comparator ............................................................... 214 comparator voltage reference settling time .......... 214 external clock........................................................... 211 i 2 c bus data (slave mode)....................................... 221 i 2 c bus data requirements (master mode) ............. 223 i 2 c bus start/stop bits (master mode) ..................... 222 i 2 c bus start/stop bits (slave mode) ....................... 220 pll clock specifications .......................................... 212 spi mode (master mode, cke = 0) .......................... 216 spi mode (master mode, cke = 1) .......................... 217 spi slave mode (cke = 1) ....................................... 219 timing requirements spi mode (slave mode, cke = 0) ............................................. 218 u uart ................................................................................ 151 baud rate generator (brg) .................................... 152 break and sync transmit sequence ........................ 153 irda support ............................................................. 153 operation of uxcts and uxrts control pins ......... 153 receiving in 8-bit or 9-bit data mode....................... 153 transmitting in 8-bit data mode ............................... 153 transmitting in 9-bit data mode ............................... 153 w watchdog timer (wdt).................................................... 186 windowed operation ................................................ 186 www address ................................................................. 257 www, on-line support ......... .............................................. 9
? 2011 microchip technology inc. ds31037b-page 255 pic24f16kl402 family the microchip web site microchip provides online support via our www site at www.microchip.com . this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com . under ?support?, click on ?customer change notification? and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://microchip.com/support
pic24f16kl402 family ds31037b-page 256 ? 2011 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip product. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to: technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds31037b pic24f16kl402 family 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2011 microchip technology inc. ds31037b-page 257 pic24f16kl402 family product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . architecture 24 = 16-bit modified harvard without dsp flash memory family f = standard voltage range flash program memory product group kl4 = general purpose microcontrollers kl3 kl2 kl1 pin count 00 = 14-pin 01 = 20-pin 02 = 28-pin temperature range i = -40 ? c to +85 ? c (industrial) package sp = spdip so = soic ss = ssop st = tssop ml, mq = qfn p=pdip pattern three-digit qtp, sqtp, code or special requirements (blank otherwise) es = engineering sample examples: a) pic24f16kl402-i/ml: general purpose, 16-kbyte program memory, 28-pin, industrial temp, qfn package b) pic24f04kl101t-i/ss: general purpose, 4-kbyte program memory, 20-pin, industrial temp, ssop package, tape-and-reel microchip trademark architecture flash memory family program memory size (kb) product group pin count temperature range package pattern pic 24 f 16 kl4 02 t - i / pt - xxx tape and reel flag (if applicable)
pic24f16kl402 family ds31037b-page 258 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds31037b-page 259 information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, pic 32 logo, rfpic and uni/o are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, hampshire, hi-tech c, linear active thermistor, mxdev, mxlab, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, app lication maestro, chipkit, chipkit logo, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, hi-tide, in-circuit serial programming, icsp, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, omniscient code generation, picc, picc-18, picdem, picdem.net, pickit, pictail, real ice, rflab, select mode, total endurance, tsharc, uniwindriver, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2011, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. isbn: 978-1-61341-811-6 note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the most secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconduc tor manufacturer can guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvin g the code protection features of our products. attempts to break microchip?s code protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
ds31037b-page 260 ? 2011 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://www.microchip.com/ support web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 indianapolis noblesville, in tel: 317-773-8323 fax: 317-773-5453 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8569-7000 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - chongqing tel: 86-23-8980-9588 fax: 86-23-8980-9500 china - hangzhou tel: 86-571-2819-3187 fax: 86-571-2819-3189 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4123 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-5778-366 fax: 886-3-5770-955 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-330-9305 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 worldwide sales and service 08/02/11


▲Up To Search▲   

 
Price & Availability of PIC24F04KL100

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X